Docker centos7 Chinese chaos problem solution

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

Docker centos7 Chinese chaos problem solution
CentOS7 and Docker configuration Chinese character set problem
Docker installation (CentOS7 installation)
Centos7 install Docker
Centos7 install docker18
centos7 install docker
CentOS7 docker installation
CentOS 6 install Docker
Centos8 install Docker
Solve the problem that Centos8 cannot install docker
CentOS 8.0 installs docker error
CentOS 8-dnf install docker
install Docker on centos6.5
Docker CentOS installation method
centos7 install keepalived problem
CentOS 7 install Docker CE
Centos7 docker installation details
Build docker environment under Centos6.5
Install docker transfer on Centos7
Install docker on Centos system
CentOS environment installation of Docker
Docker EE installation on centos7