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
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次 .NET某旅行社酒店管理系统 卡死分析
· 长文讲解 MCP 和案例实战
· Hangfire Redis 实现秒级定时任务,使用 CQRS 实现动态执行代码
· Android编译时动态插入代码原理与实践
· 解锁.NET 9性能优化黑科技:从内存管理到Web性能的最全指南
· 一天 Star 破万的开源项目「GitHub 热点速览」
· 瞧瞧别人家的日期处理,那叫一个优雅!
· 使用TypeScript开发微信小程序(云开发)-入门篇
· 没几个人需要了解的JDK知识,我却花了3天时间研究
· 定时任务稳定性解决方案-healthchecks监控系统