[root@localhost ~]# docker run -it -d centos:7
[root@650da1307bb1 /]# echo $LANG
[root@650da1307bb1 /]# locale # 查看当前系统所使用的字符集
LANG=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
[root@650da1307bb1 /]# locale -a | grep CN # 默认没有中文
[root@650da1307bb1 /]# locale -a | grep zh
[root@650da1307bb1 /]# locale -a
C
POSIX
en_AG
en_AG.utf8
en_AU
en_AU.iso88591
en_AU.utf8
en_US
en_US.iso88591
en_US.iso885915
en_US.utf8
[root@650da1307bb1 /]# yum install -y kde-l10n-Chinese # 需要执行命令进行安装
[root@650da1307bb1 /]# yum reinstall -y glibc-common
[root@650da1307bb1 /]# yum groupinstall "fonts" -y
[root@650da1307bb1 /]# yum install -y system-config-language
[root@650da1307bb1 /]# localedef -c -f UTF-8 -i zh_CN zh_CN.UFT-8 # 定义字符集
[root@650da1307bb1 /]# localedef -c -f GBK -i zh_CN zh_CN.GBK
[root@650da1307bb1 /]# localedef -c -f GB2312 -i zh_CN zh_CN.GB2312
[root@650da1307bb1 /]# locale -a
C
POSIX
en_US.utf8
zh_CN.gb2312
zh_CN.gbk
zh_CN.uft8
[root@650da1307bb1 /]# cat /etc/locale.conf
LANG="en_US.UTF-8"
[root@650da1307bb1 /]# echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf # 修改系统字符集
[root@650da1307bb1 /]# cat /etc/locale.conf
LANG="zh_CN.UTF-8"
[root@650da1307bb1 /]# source /etc/locale.conf
[root@650da1307bb1 /]# echo 'export LC_ALL="zh_CN.utf8"' >> /etc/profile
[root@650da1307bb1 /]# source /etc/profile
[root@650da1307bb1 /]# locale
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.uft8"
LC_NUMERIC="zh_CN.uft8"
LC_TIME="zh_CN.uft8"
LC_COLLATE="zh_CN.uft8"
LC_MONETARY="zh_CN.uft8"
LC_MESSAGES="zh_CN.uft8"
LC_PAPER="zh_CN.uft8"
LC_NAME="zh_CN.uft8"
LC_ADDRESS="zh_CN.uft8"
LC_TELEPHONE="zh_CN.uft8"
LC_MEASUREMENT="zh_CN.uft8"
LC_IDENTIFICATION="zh_CN.uft8"
LC_ALL=zh_CN.uft8
#### 如果还出现乱码,执行以下命令 ####
[root@650da1307bb1 fonts]# cd /usr/share/fonts/
[root@650da1307bb1 fonts]# fc-cache -fv
#### 生成镜像 ##########
docker commit -m 'test' e265924baa80 centos:7-utf8
########### dockerfile ##############################################
FROM centos:7
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& yum -y install kde-l10n-Chinese \
&& yum -y reinstall glibc-common \
&& localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8 \
&& echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf \
&& source /etc/locale.conf \
&& yum clean all
ENV LANG=zh_CN.UTF-8 \
LC_ALL=zh_CN.UTF-8