docker

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > 云和虚拟化 > docker > docker容器设置中文环境

docker容器设置中文环境的详细教程

作者:tomorrow.hello

这篇文章主要介绍了docker容器设置中文环境的详细教程,包括进入容器查看已有语言包、安装中文语言环境、写入bash.bashrc和profile文件以及重启容器,文中通过代码介绍的非常详细,需要的朋友可以参考下

1.容器中安装和设置 

1.1.进入容器查看已有语言包

locale -a

默认情况下:

1.2 安装中文语言环境

如果没有zh_CN.utf8就安装。

方式1:

#直接安装中文语言包
apt-get install -y language-pack-zh-hans

方式2:

#安装中文语言环境
apt-get install -y locales
#生成中文环境
echo "zh_CN.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen

1.3 写入 bash.bashrc 文件

echo -e "\n# chinese zh_CN.UTF-8" >> /etc/bash.bashrc
echo -e "export LANG=\"zh_CN.UTF-8\"" >> /etc/bash.bashrc
echo -e "export LANGUAGE=\"zh_CN.UTF-8\"" >> /etc/bash.bashrc
echo -e "export LC_ALL=\"zh_CN.UTF-8\"" >> /etc/bash.bashrc

1.4 写入 profile 文件

echo -e "\n# chinese zh_CN.UTF-8" >> /etc/profile
echo -e "export LANG=\"zh_CN.UTF-8\"" >> /profile
echo -e "export LANGUAGE=\"zh_CN.UTF-8\"" >> /etc/profile
echo -e "export LC_ALL=\"zh_CN.UTF-8\"" >> /etc/profile

1.5 重启容器

docker restart

2. dockerfile中安装和设置

# 容器来源
FROM 

# 换国内镜像,DEB822 格式
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources

# 更新系统
RUN apt -y update && apt -y upgrade

# 安装中文环境
RUN apt install -y locales && \
echo 'zh_CN.UTF-8 UTF-8' >> /etc/locale.gen && \
locale-gen
#或者使用这种方式安装中文环境
#run apt-get install -y language-pack-zh-hans

# 设置中文
RUN echo '\n# chinese zh_CN.UTF-8\n\
export LANG="zh_CN.UTF-8"\n\
export LANGUAGE="zh_CN.UTF-8"\n\
export LC_ALL="zh_CN.UTF-8"\n' >> /etc/bash.bashrc

RUN echo '\n# chinese zh_CN.UTF-8\n\
export LANG="zh_CN.UTF-8"\n\
export LANGUAGE="zh_CN.UTF-8"\n\
export LC_ALL="zh_CN.UTF-8"\n' >> /etc/profile

总结 

到此这篇关于docker容器设置中文环境的文章就介绍到这了,更多相关docker容器设置中文环境内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文