进入容器内部:
docker exec -t -i 容器名 /bin/bash
查看容器的语言环境:
[root@c50d94136d8c /]# locale
LANG=
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=
查看容器支持的语言:
[root@c50d94136d8c /]# locale -a
C
POSIX
en_US.utf8
zh_CN.utf8
设置字符集为zh.CN.utf8:
[root@c50d94136d8c zhai]# LANG=zh.CN.utf8
重新加载环境变量:
[root@c50d94136d8c zhai]# source /etc/profile
再次查看:
[root@security zhai]# locale
LANG=
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
注意:这样修改只是临时修改。要永久修改,需要在创建容器时在dockerfile中设置。
DOCKER_FILE_CONTENT=$DOCKER_FILE_CONTENT'ENV LANG zh_CN.UTF-8\n'
DOCKER_FILE_CONTENT=$DOCKER_FILE_CONTENT'ENV LC_ALL zh_CN.UTF-8\n'
重建构建容器后,进入容器,查看locale:
[root@f31a974e1710 /]# locale
LANG=zh_CN.UTF-8
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
修改成功!
网友评论