当前位置: 移动技术网 > 网络运营>服务器>虚拟主机 > Docker解决终端无法输入中文的问题

Docker解决终端无法输入中文的问题

2020年08月17日  | 移动技术网网络运营  | 我要评论
前言: 某日在docker里搭建了一套mysql服务,发现在mysql命令行内无法输入中文 中文显示也以?代替,起初以为是mysql字符集的问题 检查之后未解决问题,又退出到容器终端 发现同样

前言:

某日在docker里搭建了一套mysql服务,发现在mysql命令行内无法输入中文 中文显示也以?代替,起初以为是mysql字符集的问题 检查之后未解决问题,又退出到容器终端 发现同样不能输入中文,由此推断 是系统字符集出现问题,现将解决过程记录如下:

未解决前:

# 进入容器 查看字符集
[root@master2 ~]# docker exec -it b18f56aa1e15 /bin/bash
root@b18f56aa1e15:/# locale
lang=
language=
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=
# 查看容器支持的字符集
root@b18f56aa1e15:/# locale -a
c
c.utf-8
posix

不能输入中文原因:系统使用的是posix字符集,posix字符集是不支持中文的,而c.utf-8是支持中文的 只要把系统中的环境 lang 改为"c.utf-8"格式即可解决问题

只要这样进入容器即可输入中文: docker exec -it b18f56aa1e15 env lang=c.utf-8 /bin/bash

[root@master2 ~]# docker exec -it b18f56aa1e15 env lang=c.utf-8 /bin/bash
root@b18f56aa1e15:/# 你好
root@b18f56aa1e15:/# mysql -uroot -p
enter password: 
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 80
server version: 5.7.17-log mysql community server (gpl)

copyright (c) 2000, 2016, oracle and/or its affiliates. all rights reserved.

oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.

type 'help;' or '\h' for help. type '\c' to clear the current input statement.

mysql> 你好

注意:

这样修改只是临时修改。要永久修改,需要在创建容器时在dockerfile中设置。
k8s进入pod不能输入中文 也可用此方法解决。

以上就是docker解决终端无法输入中文的问题的详细内容,更多关于docker解决无法输入中文的资料请关注移动技术网其它相关文章!

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网