Alpine Docker image font problem solving operations

Alpine Docker image font problem solving operations

1. Run fonts, open the font folder, and find the font file you want to use;

2. Modify Dockerfile, for example:

FROM alpine-jdk 
ADD ./test.jar /opt/App/test.jar
#Copy the font file COPY ./simhei.ttf /usr/share/fonts/simhei.ttf 
#Set 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"]

Supplement: Dockerfile builds Alpine image/Linux uses apk to download and set resources (font package/other) failure/difficulty

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": ["native.cgroupdriver=systemd"] in daemon.json

Personal Problems

When I use Dockerfile to build an image, I use the Alpine version of the base image package, and the build is always stuck.

[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 it here through this address, and then it will start to report an error if it fails to download.

[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

After trying to modify the Docker image source and failing, I started looking for other image sources.

Cause

The source address of the alpine APK mirror is in the /etc/apk/repositories file. It is a foreign mirror with an impressive download speed. It takes more than half an hour to download a few hundred KB. So we need to change the address to the domestic Ali source

Solve Demo

FROM adoptopenjdk/openjdk8-openj9:alpine-slim
MAINTAINER ****************@*****.com
RUN mkdir -p /cim-railway/auth
#Use the verification code font package for testing. The first step is to replace the apk source with the domestic Alibaba source. Without the first step, the download will be difficult to produce 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 building images without Docker

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

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

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

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • Implementation of tomcat image created with dockerfile based on alpine
  • Implementation of crawler Scrapy image created by dockerfile based on alpine
  • How to build php-nginx-alpine image from scratch in Docker
  • Perfect solution to Docker Alpine image time zone problem

<<:  How to use the Marquee tag in XHTML code

>>:  Detailed explanation of CSS to achieve the effect of illuminating the border by imitating the Windows 10 mouse

Recommend

Detailed explanation of Vue's keyboard events

Table of contents Common key aliases Key without ...

Manually implement the two-way data binding principle of Vue2.0

In one sentence: Data hijacking (Object.definePro...

MySQL tutorial thoroughly understands stored procedures

Table of contents 1. Concepts related to stored p...

How to assign a public IP address to an instance in Linux

describe When calling this interface, you need to...

Chrome monitors cookie changes and assigns values

The following code introduces Chrome's monito...

Centos builds chrony time synchronization server process diagram

My environment: 3 centos7.5 1804 master 192.168.1...

Neon light effects implemented with pure CSS3

This is the effect to be achieved: You can see th...

Discuss the development trend of Baidu Encyclopedia UI

<br />The official version of Baidu Encyclop...

Summary of MySQL usage specifications

1. InnoDB storage engine must be used It has bett...

Front-end JavaScript operation principle

Table of contents 1. What is a JavaScript engine?...