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

Web Design: When the Title Cannot Be Displayed Completely

<br />I just saw the newly revamped ChinaUI....

MySQL online log library migration example

Let me tell you about a recent case. A game log l...

Example code for implementing the wavy water ball effect using CSS

Today I learned a new CSS special effect, the wav...

JavaScript canvas implements graphics and text with shadows

Use canvas to create graphics and text with shado...

Hyperlink icon specifications: improve article readability

1. What is the hyperlink icon specification ?<...

Cross-origin image resource permissions (CORS enabled image)

The HTML specification document introduces the cr...

Native js implementation of slider interval component

This article example shares the specific code of ...

A brief talk about the diff algorithm in Vue

Table of contents Overview Virtual Dom principle ...

Do designers need to learn to code?

Often, after a web design is completed, the desig...

Super detailed steps to install zabbix3.0 on centos7

Preface Recently, part of the company's busin...

Example of implementing QR code scanning effects with CSS3

Online Preview https://jsrun.pro/AafKp/ First loo...

Practical example of nested routes in vue.js Router

Table of contents Preface Setting up with Vue CLI...

In-depth explanation of hidden fields, a new feature of MySQL 8.0

Preface MySQL version 8.0.23 adds a new feature: ...

Some suggestions for improving Nginx performance

If your web application runs on only one machine,...