docker(podman)容器設置中文環境

容器系統使用 Debian12 爲例

安裝中文環境

apt -y update && apt -y upgrade
apt install -y locales

生成中文環境

echo "zh_CN.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen

寫入 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

退出容器,重新進入,驗證中文環境,顯示 zh_CN.UTF-8

locale

中文 Dockerfile 示例

# 容器來源
FROM atomhub.openatom.cn/amd64/debian:latest

# 換國內鏡像,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 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 apt install -y nano
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章