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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值