docker构建GUI应用

添加中文支持

一般情况下,基础镜像是不支持中文的,如果app中需要显示或输入中文,在构建docker镜像的时候需要添加中文字体,并设置字体配置文件,本文以ubuntu为例构建一个支持中文gui docker镜像。

Dockerfile
FROM ubuntu:20.04
MAINTAINER zhujia "magicletters@qq.com"

COPY fonts/69-language-selector-zh-cn.conf /etc/fonts/conf.d/
COPY fonts/simsun.ttc /usr/share/fonts/

RUN export DEBIAN_FRONTEND=noninteractive; \
    export DEBCONF_NONINTERACTIVE_SEEN=true; \
    echo 'tzdata tzdata/Areas select Asia' | debconf-set-selections; \
    echo 'tzdata tzdata/Zones/Asia select Shanghai' | debconf-set-selections; \
    apt update && apt full-upgrade -y && apt install -y --no-install-recommends \
    locales \
# 省略其他依赖包
    && apt-get -qq clean \
    && rm -rf /var/lib/apt/lists/*

# Reconfigure locale
RUN locale-gen zh_CN.UTF-8 && dpkg-reconfigure locales
69-language-selector-zh-cn.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

	<match target="pattern">
    <test name="lang">
      <string>zh-cn</string>
    </test>
		<test qual="any" name="family">
			<string>serif</string>
		</test>
		<edit name="family" mode="prepend" binding="strong">
			<string>simsun</string>
		</edit>
	</match>
	<match target="pattern">
		<test qual="any" name="family">
			<string>sans-serif</string>
		</test>
    <test name="lang">
      <string>zh-cn</string>
    </test>
		<edit name="family" mode="prepend" binding="strong">
			<string>simsun</string>
		</edit>
	</match>
	<match target="pattern">
		<test qual="any" name="family">
			<string>monospace</string>
		</test>
    <test name="lang">
      <string>zh-cn</string>
    </test>
		<edit name="family" mode="prepend" binding="strong">
			<string>simsun</string>
		</edit>
	</match>

</fontconfig>