Home  >  Article  >  What to do if docker web Chinese garbled characters

What to do if docker web Chinese garbled characters

藏色散人
藏色散人Original
2022-11-28 09:32:311944browse

Solution to Chinese garbled characters in docker web: 1. Use locale to check the character set used by the system of the current container; 2. Use "locale -a" to check the character set supported by the system of the current container; 3. Modify "/etc/profile" and add the system variable LANG.

What to do if docker web Chinese garbled characters

The operating environment of this tutorial: Windows 7 system, Docker version 20.10.11, Dell G3 computer.

docker web What should I do if the Chinese characters are garbled?

Solving the problem of garbled Chinese characters in docker containers

In the command line, when inputting Chinese characters, garbled characters or typing errors occur:

Here I want to input: "Chinese", but garbled characters appear.

What to do if docker web Chinese garbled characters

And, I have created the image before and generated the container through the image.

1. Use locale to view the character set used by the system of the current container.

2. Use locale -a to check the character sets supported by the system of the current container.

3. In some blogs, it is recommended to modify /etc/profile and add system variables LANG, etc.

1)/etc/profile: This file sets environment information for each user of the system. When the user logs in for the first time, this file is executed.

And from /etc/profile Collect shell settings from the configuration file in the .d directory.

Note: Here we set global variables that can be used by all users.

2)/etc/bashrc: Execute this file for each user running the bash shell. When the bash shell is opened, this file is read.

But it can be seen that /etc/profile is only executed when the user logs in for the first time. So after you modify the file and docker commit, running the container again with the updated version will not take effect.

So, here, I modify /etc/bashrc to update the system character set variable:

export  LANG="C.UTF-8"
export LANGUAGE="C.UTF-8"
export LC_ALL="C.UTF-8"

After modification, remember to take effect:

source /etc/bash.bashrc

View through locale again Whether the system character set has been updated:

root@7bfce1075a4b:/workspace# locale
 
LANG=C.UTF-8
LANGUAGE=C.UTF-8
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_PAPER="C.UTF-8"
LC_NAME="C.UTF-8"
LC_ADDRESS="C.UTF-8"
LC_TELEPHONE="C.UTF-8"
LC_MEASUREMENT="C.UTF-8"
LC_IDENTIFICATION="C.UTF-8"
LC_ALL=C.UTF-8

Finally, you can see that you can enter Chinese on the command line normally:

root@7bfce1075a4b:/workspace# 中文

Finally, don’t forget to submit the image update: you can choose to overwrite the current Mirror, as long as the warehouse name: label name is the same as what you want to overwrite

docker commit -m="run command" -a="wkn" 7bfce1075a4b wkn/pattern-ai:torch_1.11.0_v

Run a new container through the updated mirror again:

wkn@MightyDragon:~$ docker commit -m="run command" -a="wkn" 7bfce1075a4b wkn/pattern-ai:torch_1.11.0_v1
sha256:18b066686fe87306bb1b09e2e98c89af04a23ec6054edbf3cc73bd1dc72826a7
wkn@MightyDragon:~$ docker run -v /home/wkn:/home/wkn  -it --gpus '"device=0,1"' 18b066686fe8
root@05c9c8706296:/workspace# 中文

It can be seen that Chinese can be input normally~

Recommended learning: "docker video tutorial"

The above is the detailed content of What to do if docker web Chinese garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What model is bmh-an20?Next article:What model is bmh-an20?