docker 容器中设置中文语言包的问题
如果在Docker 中采用 docker search centos
采用 docker pull docker.io/centos 下载基础镜像
这个镜像是不支持中文的,可以采用docker attach 容器ID进入容器后采用"locale"查看
可以采用“locale -a” 查看系统语言包,会发现没有中文包
解决方案:
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 (设置系统语言包)
4、ENV LC_ALL zh_CN.UTF-8 通过设置环境变量的方式设置(可以采用直接修改/etc/locale.conf 文件来实现,不过需要reboot)
5、如果采用Dockerfile 的方式,那么可以参考下面
- # 版本信息
- FROM docker.io/centos:latest
- MAINTAINER mapengfei "[email protected]"
- #设置系统编码
- 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