一:默认的centos镜像中locale 显示的是POSIX 这种是不支持中文的
[root@localhost jettoloader]# docker run -it -d harbor.jettech.com/jettechtools/centos:7.9.2009 bashbb9987d77c1bace9696c046c91dd649d84a27be468d7154bc3ce5c02776cd04d[root@localhost jettoloader]# docker exec -it bb bash[root@f55d4fa11d5c work]# localeLANG=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@f55d4fa11d5c work]# cat /etc/locale.conf LANG="en_US.UTF-8"[root@f55d4fa11d5c work]# ls /usr/share/locale/zh_CN/ [root@f55d4fa11d5c work]# localedef --list-archiveen_AGen_AG.utf8en_AUen_AU.iso88591en_AU.utf8en_BWen_BW.iso88591en_BW.utf8en_CAen_CA.iso88591en_CA.utf8en_DKen_DK.iso88591en_DK.utf8en_GBen_GB.iso88591en_GB.iso885915en_GB.utf8en_HKen_HK.iso88591en_HK.utf8en_IEen_IE.iso88591en_IE.iso885915@euroen_IE.utf8en_IE@euroen_INen_IN.utf8en_NGen_NG.utf8en_NZen_NZ.iso88591en_NZ.utf8en_PHen_PH.iso88591en_PH.utf8en_SGen_SG.iso88591en_SG.utf8en_USen_US.iso88591en_US.iso885915en_US.utf8en_ZAen_ZA.iso88591en_ZA.utf8en_ZMen_ZM.utf8en_ZWen_ZW.iso88591en_ZW.utf8[root@f55d4fa11d5c work]# rpm -qa | grep glibc-commonglibc-common-2.17-317.el7.x86_64[root@f55d4fa11d5c work]# rpm -qa | grep kde-l10n-Chinese
二,操作支持
2.1 直接编写看下能否改变成识别中文字体,
写到你的~/.bashrc里吧,然后重启终端
[root@f55d4fa11d5c work]# cat ~/.bashrc # .bashrc# User specific aliases and functionsalias rm='rm -i'alias cp='cp -i'alias mv='mv -i'# Source global definitionsif [ -f /etc/bashrc ]; then、/etc/bashrcfiexport LC_ALL=zh_CN.UTF-8export LANGUAGE=zh_CN.UTF-8export LANG=zh_CN.UTF-8[root@f55d4fa11d5c work]# source ~/.bashrc bash: warning: setlocale: LC_ALL: cannot change locale (zh_CN.UTF-8): No such file or directorybash: warning: setlocale: LC_ALL: cannot change locale (zh_CN.UTF-8)[root@f55d4fa11d5c work]# localelocale: Cannot set LC_CTYPE to default locale: No such file or directorylocale: Cannot set LC_MESSAGES to default locale: No such file or directorylocale: Cannot set LC_ALL to default locale: No such file or directoryLANG=zh_CN.UTF-8LC_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=zh_CN.UTF-8
看效果此
[root@f55d4fa11d5c work]# vi a
执行一下,转化语言环境和字符集
[root@ef3d25d5714d work]# localedef -c -f UTF-8 -i zh_CN zh_CN.utf8[root@ef3d25d5714d work]# localedef --list-archiveen_AGen_AG.utf8en_AUen_AU.iso88591en_AU.utf8en_BWen_BW.iso88591en_BW.utf8en_CAen_CA.iso88591en_CA.utf8en_DKen_DK.iso88591en_DK.utf8en_GBen_GB.iso88591en_GB.iso885915en_GB.utf8en_HKen_HK.iso88591en_HK.utf8en_IEen_IE.iso88591en_IE.iso885915@euroen_IE.utf8en_IE@euroen_INen_IN.utf8en_NGen_NG.utf8en_NZen_NZ.iso88591en_NZ.utf8en_PHen_PH.iso88591en_PH.utf8en_SGen_SG.iso88591en_SG.utf8en_USen_US.iso88591en_US.iso885915en_US.utf8en_ZAen_ZA.iso88591en_ZA.utf8en_ZMen_ZM.utf8en_ZWen_ZW.iso88591en_ZW.utf8zh_CN.utf8[root@ef3d25d5714d work]# localeLANG=zh_CN.UTF-8LC_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=zh_CN.UTF-8
在测试:
[root@f55d4fa11d5c work]# vi a
方法二:进入docker里配置
#添加中文环境编码,安装两个包 如果有的话就不用装了 我的系统默认有glibc-common 就可以了不用安装kde-l10n-Chinese [root@d547146f3672 work]# yum install kde-l10n-Chinese glibc-common -y#转化语言环境和字符集 这个是主要的[root@d547146f3672 work]# localedef -c -f UTF-8 -i zh_CN zh_CN.utf8#添加定义到系统环境变量[root@d547146f3672 work]# echo "export LC_ALL=zh_CN.utf8" >> /etc/profile执行生效[root@d547146f3672 work]# source /etc/profile[root@d547146f3672 work]# localedef --list-archiveen_US.utf8zh_CN.utf8[root@d547146f3672 work]# localeLANG=LC_CTYPE="zh_CN.utf8"LC_NUMERIC="zh_CN.utf8"LC_TIME="zh_CN.utf8"LC_COLLATE="zh_CN.utf8"LC_MonETARY="zh_CN.utf8"LC_MESSAGES="zh_CN.utf8"LC_PAPER="zh_CN.utf8"LC_NAME="zh_CN.utf8"LC_ADDRESS="zh_CN.utf8"LC_TELEPHONE="zh_CN.utf8"LC_MEASUREMENT="zh_CN.utf8"LC_IDENTIFICATION="zh_CN.utf8"LC_ALL=zh_CN.utf8
测试:
[root@d547146f3672 work]# vi a
方法三:编写dockerfile文件
[root@localhost base]# cat Dockerfile FROM harbor.jettech.com/jettechtools/centos:7.9.2009MAINTAINER wu_bo2@hoperun.comRUN yum install -y wget net-tools iproute bind-utils lrzsz && rm -rf /var/cache /tmp/* && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && localedef -c -f UTF-8 -i zh_CN zh_CN.utf8#RUN yum install kde-l10n-Chinese -y#RUN yum install glibc-common -y#RUN export LANG=zh_CN.UTF-8#RUN echo "export LANG=zh_CN.UTF-8" >> /etc/locale.conf#ENV LANG zh_CN.UTF-8ADD jre-8u321-linux-x64-minimal.tar.gz /usr/java/jdkENV LC_ALL zh_CN.UTF-8ENV JAVA_HOME /usr/java/jdkENV PATH ${PATH}:${JAVA_HOME}/binWORKDIR /jettech/work
制作 docker 精简 jre8 基础镜像
官方jre下载地址:https://www.java.com/en/download/manual.jsp
然后解压JRE包,删除根目录下文本文件,然后删除其他不必要文件,命令如下:
# 解压[root@localhost base]#tar -zxvf jre-8u321-linux-x64.tar.gz# 进入目录[root@localhost base]#cd jre1.8.0_321/# 删除文本文件[root@localhost base]#rm -rf COPYRIGHT LICENSE README release THIRDPARTYLICENSEREADME-JAVAFX.txt THIRDPARTYLICENSEREADME.txt Welcome.html#删除其他无用文件[root@localhost base]# rm -rf lib/plugin.jar lib/ext/jfxrt.jar bin/javaws lib/javaws.jar lib/desktop plugin lib/deploy* lib/*javafx* lib/*jfx* lib/amd64/libdecora_sse.so lib/amd64/libprism_*.so lib/amd64/libfxplugins.so lib/amd64/libglass.so lib/amd64/libgstreamer-lite.so lib/amd64/libjavafx*.so lib/amd64/libjfx*.so
重新打包
# 打包,包名增加 -minimal 和原始包名进行区分[root@localhost base]# tar -zcvf jre-8u321-linux-x64-minimal.tar.gz *
构建镜像
[root@localhost base]# cp jre-8u321-linux-x64-minimal.tar.gz work/[root@localhost base]# docker build -t harbor.jettech.com/jettechtools/centos-jre-8:7.9.2009 -f Dockerfile work/
Docker Hub
https://github.com/CentOS/sig-cloud-instance-images/tree/CentOS-7-x86_64/docker
https://github.com/CentOS/sig-cloud-instance-build