0


docker 容器设置中文环境

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 容器 运维

本文转载自: https://blog.csdn.net/myli92/article/details/139909499
版权归原作者 tomorrow.hello 所有, 如有侵权,请联系我们删除。

“docker 容器设置中文环境”的评论:

还没有评论