DOCKER中centos7的中文支持
直接编写看下能否改变成识别中文字体
写到你的~/.bashrc里吧,然后重启终端(我写的是英文的啊,改成你要的)
1 2 3 | export LC_ALL=en_US.UTF-8 export LANGUAGE=en_US.UTF-8 export LANG=en_US.UTF-8 |
不行的话就老老实实使用下面的方法
方法一:进入docker里配置
1 2 3 4 5 6 7 8 9 10 | 添加中文环境编码,安装两个包 # yum install kde-l10n-Chinese -y # yum install glibc-common -y 转化语言环境和字符集 # localedef -c -f UTF-8 -i zh_CN zh_CN.utf8 添加定义到系统环境变量 # vi /etc/profile export LC_ALL=zh_CN.utf8 执行生效 # source /etc/profile |
方法二:编写dockerfile文件
1 2 3 4 5 6 7 8 9 10 | FROM centos MAINTAINER djl #设置系统编码 RUN yum install kde-l10n-Chinese -y RUN yum install glibc-common -y RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8 #RUN export LANG=zh_CN.UTF-8 #RUN echo "export LANG=zh_CN.UTF-8" >> /etc/locale.conf #ENV LANG zh_CN.UTF-8 ENV LC_ALL zh_CN.UTF-8 |
自己在实践中编写的dockerfile实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | FROM centos:7 MAINTAINER nsh RUN yum -y localinstall http: //nginx .org /packages/centos/7/noarch/RPMS/nginx-release-centos-7-0 .el7.ngx.noarch.rpm && \ yum -y install nginx && \ yum -y install kde-l10n-Chinese && \ yum -y install glibc-common -y && \ rpm -Uvh https: //dl .fedoraproject.org /pub/epel/epel-release-latest-7 .noarch.rpm && \ rpm -Uvh https: //mirror .webtatic.com /yum/el7/webtatic-release .rpm && \ yum -y install php72w php72w-fpm php72w-mbstring php72w-common php72w-gd php72w-mysqlnd php72w-xml php72w-cli php72w-devel php72w-pecl-memcached php72w-pecl-redis php72w-opcache php72w-pecl-redis php72w-bcmath php72w-gd php72w-mysqli ADD nginx.conf /etc/nginx/nginx .conf RUN mkdir /code RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8 WORKDIR /code ADD cs. tar .gz . ###这里是自己项目的包 ENV LC_ALL zh_CN.UTF-8 RUN chown -R apache.apache . RUN chown -R apache.apache /var/log/nginx EXPOSE 80 ADD init.sh /init .sh CMD [ "/bin/bash" , "/init.sh" ] |
之后我进入容器中测试(创建中文文件夹和在文件中编辑中文)
亲测有效..........................
参考博客:
Dockerfile 创建容器内中文乱码问题解决
https://blog.csdn.net/weixin_39153210/article/details/83617792
解决docker容器中Centos7系统的中文乱码
https://blog.csdn.net/xw_2_xh/article/details/86497636
centos7在docker环境中乱码问题
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix