Using the docker centos7 image to deploy the springboot project, I found garbled characters in the log file. This problem is mostly caused by the lack of support for Chinese in the mirror. The following is a specific solution.
Enter the container according to the container name or id:
docker exec -it container_name /bin/bash
Execute locale to check the language used in the current environment:
[ root@f6179ac439f2 /]# 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=
Execute locale -a to view the language packs supported by the current system:
[ root@f6179ac439f2 /]# locale -a
C
POSIX
en_US.utf8
You will find that Chinese zh_CN.utf8 is not supported by default. Now start to install the corresponding language pack.
Install language pack (for centos 7):
yum install kde-l10n-Chinese -y
Update the gitbc package (to prevent mirror castration of part of the package's functions):
yum reinstall glibc-common -y
Set the system language pack:
localedef -c -f UTF-8-i zh_CN zh_CN.utf8
Added in the /etc/profile file:
export LC_ALL=zh_CN.UTF-8
Recompile:
source /etc/profile
Set /etc/locale.conf, add:
LANG="zh_CN.UTF-8"
Then restart the mirror, the garbled problem is solved. Although the locale is executed again, the displayed code is still POSIX, but the log garbled problem no longer exists.
The above method is to solve the situation where the docker image and container already exist. If you want to solve this problem while making the image, you can add the following configuration in the Dockerfile:
RUN yum install kde-l10n-Chinese -y
RUN yum install glibc-common -y
RUN localedef -c -f UTF-8-i zh_CN zh_CN.utf8
RUN export LANG=zh_CN.UTF-8
RUN echo "export LANG=zh_CN.UTF-8">>/etc/locale.conf
ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
Recommended Posts