docker基础-locale语言环境

摘要

本文部分内容来源于网络,个人收集整理,请勿传播

待续。。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
最近的项目中Docker容器中生成的日志文件是中文名字,但是文件名是????.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



修改成功!