Docker does not support Chinese by default. When the Java runtime environment is deployed in Docker, the logs are garbled and ????

First, look at the encoding format supported in the container

Enter the container method portal as follows:

4 ways Docker enters containers

After the restart, run the following command to view the encoding format in the container:

[root@584c4789c688 caseexportfile]# 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=
Copy the code

The POSIX encoding does not support Chinese

[root@584c4789c688 caseexportFile]# mkdir Who am I? [root@584c4789c688 caseexportfile]# ls ??? ???????????????????? ????Copy the code

2. Specify the encoding environment through Dockerfile

ENV LC_ALL=zh_CN.utf8
ENV LANG=zh_CN.utf8
ENV LANGUAGE=zh_CN.utf8
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
Copy the code

Three, enter the container to view, code change, support Chinese

[root@localhost caseexportfile]# 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=
Copy the code

Apply Chinese garble to this container to solve the problem.