
正文
DOCKER中centos7的中文支持
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
直接编写看下能否改变成识别中文字体
写到你的~/.bashrc里吧,然后重启终端(我写的是英文的啊,改成你要的)
export LC_ALL=en_US.UTF-8export LANGUAGE=en_US.UTF-8export LANG=en_US.UTF-8
不行的话就老老实实使用下面的方法
方法一:进入docker里配置
添加中文环境编码,安装两个包# yum install kde-l10n-Chinese -y# yum install glibc-common -y转化语言环境和字符集# localedef -c -f UTF-8 -i zh_CN zh_CN.utf8添加定义到系统环境变量# vi /etc/profileexport LC_ALL=zh_CN.utf8执行生效# source /etc/profile
方法二:编写dockerfile文件
FROM centosMAINTAINER djl#设置系统编码RUN yum install kde-l10n-Chinese -yRUN yum install glibc-common -yRUN 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-8ENV LC_ALL zh_CN.UTF-8
自己在实践中编写的dockerfile实例
FROM centos:7MAINTAINER nshRUN 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-mysqliADD nginx.conf /etc/nginx/nginx.confRUN mkdir /codeRUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8WORKDIR /codeADD cs.tar.gz . ###这里是自己项目的包ENV LC_ALL zh_CN.UTF-8RUN chown -R apache.apache .RUN chown -R apache.apache /var/log/nginxEXPOSE 80ADD init.sh /init.shCMD ["/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环境中乱码问题
https://www.cnblogs.com/djlsunshine/p/11282867.html






