容器系統使用 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