CentOS7 and Docker configuration Chinese character set problem

Author: willblog, original: https: //blog.csdn.net/networken/article/details/97951173

Description##

The Linux system uses the English character set by default, and other characters such as the Chinese character set will not be installed.

View current character set

$ echo $LANG
en_US.UTF-8

Install character set
Use the locale command to see the character set used by the current system

$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Check whether the system has Chinese character set support

# locale -a | grep CN
bo_CN
bo_CN.utf8
ug_CN
ug_CN.utf8
zh_CN
zh_CN.gb18030
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8

If you did not execute the following command to install

# CentOS6.x:
yum groupinstall chinese-support

# CentOS7.x
yum install -y kde-l10n-Chinese
yum reinstall -y glibc-common

# Define character set
localedef -c -f UTF-8-i zh_CN zh_CN.UFT-8
# Confirm successful loading
locale -a

Modify the system character set
Modify the configuration file of the system character set:

# echo 'LANG="zh_CN.UTF-8"'>/etc/locale.conf
# source /etc/locale.conf

Or temporarily change the character set:

LANG="<character set>"
LANG="zh_CN.UTF-8"

# Or write character set environment variables to profile
vim /etc/profile
source /etc/profile

Verify character set modification

# echo $LANG
zh_CN.UTF-8

# 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=

Modify the ssh terminal character set

If you follow the above method to modify the settings of the Chinese language, it still does not work, pay attention to the encoding selected by the SSH terminal, such as xshell, for example, select Chinese or UTF8 as the encoding of the terminal.
If the system interface still appears garbled, install the following packages:

yum groupinstall "fonts"-y

If it is still garbled, enter the fonts installation path and execute the following command
[ root@localhost ~]# cd /usr/share/fonts/[root@localhost ~]# fc-cache -fv

Container environment configuration character set##

Take CentOS7 container image as an example
View the default configuration

# docker run -it --rm centos sh
sh-4.2# echo $LANG

sh-4.2# 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=

sh-4.2# locale -a
C
POSIX
en_US.utf8

Take the configuration of zh_CN.GB18030 character set as an example

yum install -y kde-l10n-Chinese
yum reinstall -y glibc-common
localedef -c -f GB18030 -i zh_CN zh_CN.GB18030

# Verify that the Chinese language pack is loaded successfully zh_CN.gb18030
# locale -a
C
POSIX
en_US.utf8
zh_CN.gb18030

Modify character set configuration

$ cat /etc/locale.conf 
LANG="en_US.UTF-8"
$ echo 'LANG="zh_CN.GB18030"'>/etc/locale.conf && source /etc/locale.conf
$ echo "export LC_ALL=zh_CN.GB18030">>/etc/profile && source /etc/profile

# Verify that the configuration takes effect
$ echo $LANG
zh_CN.GB18030

Dockerfile example:

The docker container environment needs to make the corresponding character set image based on the dockerfile, and add the following content to the custom dockerfile:

# cat Dockerfile
FROM centos
LABEL Maintainer dockerhub.com
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
 && yum -y install kde-l10n-Chinese \
 && yum -y reinstall glibc-common \
 && localedef -c -f GB18030 -i zh_CN zh_CN.GB18030 \
 && echo 'LANG="zh_CN.GB18030"'>/etc/locale.conf \
 && source /etc/locale.conf \
 && yum clean all 
ENV LANG=zh_CN.GB18030 \
 LC_ALL=zh_CN.GB18030

Recommended Posts

CentOS7 and Docker configuration Chinese character set problem
Docker centos7 Chinese chaos problem solution
Centos mysql installation and configuration
Centos7 installation and configuration prometheus
CentOS 7 installation and configuration PPTP
CentOS installation and configuration cmake
Centos7.5 installation and configuration MongoDB4.0.4
CentOS 7 installation and configuration PPTP
Centos7 installation and configuration of Jenkins
CentOS 8 install Git and basic configuration
Centos7 hadoop cluster installation and configuration
CentOS7.2 and Nginx configuration virtual host
Java-JDK installation and configuration under CentOS
Install and use docker under CentOS 6.8
CentOS 7 Tomcat service installation and configuration
Centos 7 RAID 5 detailed explanation and configuration
Ubuntu 19.1 installation and configuration Chinese environment
CentOS NTP server installation and configuration
Centos7 mysql database installation and configuration
CentOS 7 system installation and configuration graphic tutorial
Tomcat installation and configuration under CentOS 7 (Tomcat startup)
MySQL 8.0 installation, deployment and configuration under CentOS 6/7
Centos7 compile and install MySQL8 problem record
Deploy Docker and configure Nginx in CentOS
Centos7 hive stand-alone mode installation and configuration
Centos7 configuration host name and IP address
Installation and configuration of JDK in CentOS 7 system
How to install and use Docker on CentOS 7
CentOS 6.5 system installation and configuration graphic tutorial (detailed graphic)
CentOS 7 installation and configuration graphic tutorials under VMware10
Centos7.6 dual network card configuration and switching test
Install svn and configuration through yum under CentOS
Installation and configuration of rsync server under CentOS 6.5
Installation and configuration of CentOS 7 in VMware Workstation
CentOS7 Docker Nginx deployment and operation detailed explanation
Installing CentOS 6 and SSH configuration under Windows 8 Hyper-V
MySQL 8.0 installation, deployment and configuration tutorial on CentOS 8
CentOS 7 install Docker
CentOS7.0 network configuration
CentOS 7.0 network configuration
CentOS7 install Docker
CentOS7 basic configuration
Docker installation (CentOS7 installation)
Centos7 install Docker
Centos7 install docker18
centos7 install docker
CentOS7 docker installation
CentOS 6 install Docker
Centos8 install Docker
Centos MySQL8 configuration
[Linux]Ubuntu set root password and solve xShell connection problem
Environment configuration of JDK, mysql and tomcat under Centos7
Linux firewall related configuration commands and operations (centos and ubuntu)