Ubuntu容器设置语言为中文

Ubuntu Docker容器默认语言是英文,我们要把它设置为中文,这里用的Ubuntu版本是20.04。

  1. 首先查看当前语言
    locale

输出如下

LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
  1. 查看当前已安装的语言
locale -a

输出如下

C
C.UTF-8
POSIX
  1. 安装语言包
apt install -y language-pack-zh-hans
locale-gen zh_CN.UTF-8

再次查看已安装的语言

locale -a

输出变为

C
C.UTF-8
POSIX
zh_CN.utf8
zh_SG.utf8
  1. 添加到profile
echo "export LC_ALL=zh_CN.UTF-8">> /etc/profile
source /etc/profile
  1. 再次查看当前语言
locale

正常的话输出如下

LANG=
LANGUAGE=
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=zh_CN.UTF-8

最后重启Docker容器即可。

Leave a Comment

豫ICP备19001387号-1