博客是我工作的好帮手,遇到困难就来博客找资料
分类: 系统运维
2017-01-17 14:47:07
最近的项目中容器中生成的日志文件是中文名字,但是文件名是????.txt
进入容器内部:
docker exec -t -i 容器名 /bin/bash
查看容器的语言环境:
[root@12ec64254bc4 /]# 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@12ec64254bc4 /]# locale -a
C
POSIX
en_US.utf8
zh_CN.utf8
设置字符集为zh.CN.utf8:
[root@12ec64254bc4 zhai]# LANG=zh.CN.utf8
重新加载环境变量:
[root@12ec64254bc4 zhai]# source /etc/profile
再次查看:
[root@12ec64254bc4 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@d18364b14af9 /]# 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
修改成功!