直接编写看下能否改变成识别中文字体
写到你的~/.bashrc里吧,然后重启终端(我写的是英文的啊,改成你要的)
export LC_ALL=en_US.UTF-8 export LANGUAGE=en_US.UTF-8 export 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/profile export LC_ALL=zh_CN.utf8 执行生效 # source /etc/profile
方法二:编写dockerfile文件
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实例
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环境中乱码问题
https://www.cnblogs.com/djlsunshine/p/11282867.html