当前位置: 首页> 科技> 数码 > docker 容器设置中文环境

docker 容器设置中文环境

时间:2025/7/9 0:03:46来源:https://blog.csdn.net/myli92/article/details/139909499 浏览次数:0次

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.bashrcRUN 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 容器设置中文环境

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: