Docker基础镜像debain的乱码问题

问题

公司内的项目在进行容器化并实现DevOps的时候,由于代码文件编码的问题,出现了乱码问题,在windows环境下,正常没有问题,首先看一下前期基于debain+nodejs+ionic构建的用于项目打包的基础镜像,镜像文件如下所示:

FROM 10.10.70.65/base/andreptb/maven:3.3.9-jdk8
COPY settings.xml /usr/share/maven/conf/settings.xml
COPY linux-x64-57_binding.node /usr/local/
ENV SASS_BINARY_PATH=/usr/local/linux-x64-48_binding.node
COPY node-v8.6.0-linux-x64.tar.gz /home/node-v8.6.0-linux-x64.tar.gz
WORKDIR /home/
RUN tar xvf node-v8.6.0-linux-x64.tar.gz
&& mv node-v8.6.0-linux-x64/ /usr/local/
RUN echo ‘’ > /etc/apt/sources.list.d/jessie-backports.list
&& echo “deb http://mirrors.aliyun.com/debian jessie main contrib non-free” > /etc/apt/sources.list
&& echo “deb http://mirrors.aliyun.com/debian jessie-updates main contrib non-free” >> /etc/apt/sources.list
&& echo “deb http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free” >> /etc/apt/sources.list

RUN apt-get update && apt-get install -y libltdl7
RUN export PATH=/usr/local/node-v8.6.0-linux-x64/bin:$PATH
&& npm config set registry https://registry.npm.taobao.org
&& npm install -g @angular/cli
&& npm install uglify-js -g
&& npm install -g cordova
&& npm install -g ionic
ENV PATH=/usr/local/node-v8.6.0-linux-x64/bin:$PATH
基于上述镜像,制作的war包,对于中文,会出现乱码问题,如下所示

<display-name>????????????????????????</display-name>
<context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>dfweb.root</param-value>
</context-param>

尝试在pom.xml上增加以下配置,并未解决问题,但是这应该是必须的配置
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
在windows环境和centos 环境下进行了mvn package,都未出现乱码问题,最终怀疑是基础镜像的语言环境问题,查看Centos7的语言环境如下所示:
[root@RD65 ~]# 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=
查看基础镜像的语言环境如下所示:

root@82f9c92e247c:/home# 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=

解决方法

修改基础镜像的Dockerfile

FROM 10.10.70.65/base/andreptb/maven:3.3.9-jdk8
COPY settings.xml /usr/share/maven/conf/settings.xml
COPY linux-x64-57_binding.node /usr/local/
ENV SASS_BINARY_PATH=/usr/local/linux-x64-48_binding.node
COPY node-v8.6.0-linux-x64.tar.gz /home/node-v8.6.0-linux-x64.tar.gz
WORKDIR /home/
RUN tar xvf node-v8.6.0-linux-x64.tar.gz
&& mv node-v8.6.0-linux-x64/ /usr/local/
RUN echo ‘’ > /etc/apt/sources.list.d/jessie-backports.list
&& echo “deb http://mirrors.aliyun.com/debian jessie main contrib non-free” > /etc/apt/sources.list
&& echo “deb http://mirrors.aliyun.com/debian jessie-updates main contrib non-free” >> /etc/apt/sources.list
&& echo “deb http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free” >> /etc/apt/sources.list

RUN apt-get update && apt-get install -y libltdl7
RUN export PATH=/usr/local/node-v8.6.0-linux-x64/bin:$PATH
&& npm config set registry https://registry.npm.taobao.org
&& npm install -g @angular/cli
&& npm install uglify-js -g
&& npm install -g cordova
&& npm install -g ionic
ENV PATH=/usr/local/node-v8.6.0-linux-x64/bin:$PATH

#config locale
RUN sed -i -e ‘s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/‘ /etc/locale.gen &&
locale-gen
ENV LANGUAGE=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8