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

Five guidelines to help you write maintainable CSS code

1. Add a comment block at the beginning of the sty...

Detailed example of locating and optimizing slow query sql in MySQL

Table of contents 1. How to locate and optimize s...

Detailed explanation of anonymous slots and named slots in Vue

Table of contents 1. Anonymous slots 2. Named slo...

How to replace all tags in html text

(?i) means do not match case. Replace all uppercas...

Linux uses suid vim.basic file to achieve privilege escalation

Reproduce on Kali First set suid permissions for ...

Detailed explanation of how to use Vue self-nested tree components

This article shares with you how to use the Vue s...

How to inherit CSS line-height

How is Line-height inherited?Write a specific val...

Summary of knowledge points about covering index in MySQL

If an index contains (or covers) the values ​​of ...

Solve the mobile terminal jump problem (CSS transition, target pseudo-class)

Preface Many friends who have just come into cont...

How to run py files directly in linux

1. First create the file (cd to the directory whe...

Implementation of Single Div drawing techniques in CSS

You can often see articles about CSS drawing, suc...

A Deep Dive into JavaScript Promises

Table of contents 1. What is Promise? 2. Why is t...

Common naming rules for CSS classes and ids

Public name of the page: #wrapper - - The outer e...

Detailed explanation of the principle and usage of MySQL views

This article uses examples to illustrate the prin...