docker 容器中设置中文语言包的问题

如果在Docker 中采用 docker search centos

docker 容器中设置中文语言包的问题

采用 docker pull docker.io/centos 下载基础镜像

docker 容器中设置中文语言包的问题

这个镜像是不支持中文的,可以采用docker attach 容器ID进入容器后采用"locale"查看

docker 容器中设置中文语言包的问题

可以采用“locale -a” 查看系统语言包,会发现没有中文包

docker 容器中设置中文语言包的问题

解决方案:

1、yum install kde-l10n-Chinese -y 安装语言包(针对centos 7)

2、yum reinstall glibc-common -y 更新gitbc 包(因为该镜像已阉割了该包的部分功能,所以需要更新)

3、localedef -c -f UTF-8 -i zh_CN zh_CN.utf8 (设置系统语言包)

docker 容器中设置中文语言包的问题

4、ENV LC_ALL zh_CN.UTF-8 通过设置环境变量的方式设置(可以采用直接修改/etc/locale.conf 文件来实现,不过需要reboot)

docker 容器中设置中文语言包的问题

5、如果采用Dockerfile 的方式,那么可以参考下面

 

  1. # 版本信息
  2. FROM docker.io/centos:latest
  3. MAINTAINER mapengfei "[email protected]"
  4. #设置系统编码
  5. RUN yum install kde-l10n-Chinese -y
  6. RUN yum install glibc-common -y
  7. RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
  8. #RUN export LANG=zh_CN.UTF-8
  9. #RUN echo "export LANG=zh_CN.UTF-8" >> /etc/locale.conf
  10. #ENV LANG zh_CN.UTF-8
  11. ENV LC_ALL zh_CN.UTF-8