Troubleshooting of Alpine Docker Mirrored Fonts

  • 2021-10-25 00:14:43
  • OfStack

1. Run fonts, open the font folder and find the font file to be used;

2. Modify Dockerfile, for example:


FROM alpine-jdk 
ADD ./test.jar /opt/App/test.jar
# Copy font file 
COPY ./simhei.ttf /usr/share/fonts/simhei.ttf 
# Set the character set 
ENV LANG en_US.UTF-8
# Install font software and complete font configuration 
RUN apk add --update ttf-dejavu fontconfig && rm -rf /var/cache/apk/* 
WORKDIR /opt/App/ 
EXPOSE 8080 
ENTRYPOINT ["java", "-jar"] 
CMD ["test.jar"]

Added: Dockerfile Build Alpine Imager/Linux Download Settings Resource (Font Pack/Other) Failure/Dystocia with apk

Note before building

If this error is reported:

OCI runtime create failed: systemd cgroup flag passed, but systemd support for managing cgroups is not available: unknown

Please delete "exec-opts" in daemon. json: ["native. cgroupdriver=systemd"]

Personal problems

When I use Dockerfile to build an image, I use the basic image package of Alpine version to build 1 directly to the card


[INFO] fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
[INFO] fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz

Download here through this address, and then start to report errors if you can't download it.

[ERROR] The command '/bin/sh -c set -xe & & apk --no-cache add ttf-dejavu fontconfig' returned a non-zero code: 2

Or

[ERROR] The command '/bin/sh -c set -xe & & apk --no-cache add ttf-dejavu fontconfig' returned a non-zero code: 1

Start looking for other mirror source problems after attempting to modify Docker mirror source is invalid

Causes of the problem

The source address of APK image of alpine itself is in the/etc/apk/repositories file, which is a foreign image. The download speed is touching, and hundreds of KB download takes more than half an hour. So we have to change the address to Aliyuan in China

Solve Demo


FROM adoptopenjdk/openjdk8-openj9:alpine-slim
MAINTAINER ****************@*****.com
RUN mkdir -p /cim-railway/auth
# Test with a verification code font pack. No. 1 1 Step will apk Source is replaced by domestic Ali source. No number 1 Step will download dystocia 
RUN echo -e 'https://mirrors.aliyun.com/alpine/v3.6/main/\nhttps://mirrors.aliyun.com/alpine/v3.6/community/' > /etc/apk/repositories \
 && apk update \
 && apk upgrade \
 && apk --no-cache add ttf-dejavu fontconfig

When mirroring without Docker

Just replace the two lines of mirror address in the/etc/apk/repositories file with the following address

https://mirrors.aliyun.com/alpine/v3.6/main/

https://mirrors.aliyun.com/alpine/v3.6/community/


Related articles: