Problem background:When using docker to deploy the project, the system font is used by default when calling the print control in the project. There is no problem deploying it on Windows. However, when running it in a docker container, the system reports an error and cannot find the corresponding font because there are no related fonts such as Songti in docker. Solution:In fact, just like solving the problem that Linux itself does not have Song font, it can also be used to solve the container problem. I found that many docker container problems can actually be solved by following the Linux solution. Basically, you just need to download the Songti ttf and ttc files, then insert them into the container font directory, and restart the container. Solution:1. Check the fonts supported by the container. fc-list :lang=zh If you see the following situation, it means that font management is not installed and fonts need to be installed 2. Install the font library. yum -y install fontconfig After the installation is complete, you can see the fontconfig and fonts folders in the /usr/share directory, as shown in the figure: 3. Copy the downloaded font ttc and ttf files to the /usr/share/fonts file of the container. cp simsun.ttc container:/usr/share/fonts cp simsun.ttf container:/usr/share/fonts 4. Then restart the container and you can see the installed Chinese fonts. 5. You can also write this step into the Dockerfile and automatically implement it when building the image. Supplement: Docker | Install Chinese fonts and change utf-8 encoding in Docker container (solve Chinese garbled characters problem) 1. Project BackgroundThe development team reported that during the project operation, garbled characters appeared when using pagoffice and word to convert to pdf. This problem was solved and this record was made for review. 2. Problem AnalysisThere are two problems with garbled characters when using pagoffice and word to convert to pdf, the corresponding relationship is: pagoffice ---- UTF-8 encoding is not used, and POSIX is used by default in some docker containers. word2pdf ---- Chinese fonts are not installed in Liunx and are missing. Some Chinese fonts are installed by default in Linux and Docker containers, or there are no Chinese fonts. To sum up, in order to completely solve the container garbled problem, you need to solve: 1. Use utf-8 to support Chinese; 2. Install Chinese fonts. 3. Solution3.1. Use UTF-8 encoding to support Chinese3.1.1 Using C.UTF-8 encoding Using C.UTF-8 encoding can support Chinese. The Docker image on the official website supports and uses C.UTF-8 encoding by default. locale -a #View all language environments of the container locale #View the language environment used by the container If the image you are using is not encoded in C.UTF-8, you can change it to this encoding format by adding the following parameters when running the container: -e export LANG="C.UTF-8" 3.1.2 Other solutions You can also add parameters when starting Docker. -e export LANG="zh_CN.UTF-8" However, I used the image from the docker official website. After using the parameters, it was indeed set to use "zh_CN.UTF-8", but it was not installed. There will be an error: locale # View the set character set locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_ALL to default locale: No such file or directory LANG=zh_CN.UTF-8 LC_CTYPE="zh_CN.UTF-8" LC_NUMERIC="zh_CN.UTF-8" LC_TIME="zh_CN.UTF-8" LC_COLLATE="zh_CN.UTF-8" LC_MONETARY="zh_CN.UTF-8" LC_MESSAGES="zh_CN.UTF-8" LC_PAPER="zh_CN.UTF-8" LC_NAME="zh_CN.UTF-8" LC_ADDRESS="zh_CN.UTF-8" LC_TELEPHONE="zh_CN.UTF-8" LC_MEASUREMENT="zh_CN.UTF-8" LC_IDENTIFICATION="zh_CN.UTF-8" LC_ALL= locale -a # View installed character sets locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_COLLATE to default locale: No such file or directory C POSIX en_US.utf8 3.2. Install Chinese fonts and display Chinese3.2.1 View existing fonts View all current fonts in Linux fc-list View all current Chinese fonts in Linux fc-list :lang=zh 3.2.2 Get other fonts In Windows systems, fonts exist under C:\Windows\Fonts. After copying, upload it to the Linux server /opt/software/chinese (I want to install the font in the docker container. If you want to install the font in the Linux host, put it directly in the server's /usr/share/fonts/ folder). 3.2.2 Installing fonts in containers docker ps -a #View container docker cp /opt/software/chinese tomcat:/usr/share/fonts/ #tomcat is the container name docker exec -it tomcat /bin/bash #Enter the container chmod 644 -R chinese/ Authorization folder fc-list :lang=zh #View Chinese fonts fc-cache -fv # Refresh the cache 3.3. Verificationpagoffice ---- After changing the docker container, you need to restart the container word2pdf ---- refresh the font cache, no need to restart the container 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:
|
<<: CSS to achieve glowing text and a little bit of JS special effects
>>: WEB standard web page structure
1.1 Introduction to storage engines 1.1.1 File sy...
Table of contents 1. Table self-sorting 2. Paging...
Table of contents Mode Parameters HashHistory Has...
1. Download MySQL from the official website: This...
1 Introduction Thread technology was proposed as ...
Preface NAT forwarding: Simply put, NAT is the us...
The docker exec command can execute commands in a...
During development, I encountered such a requireme...
Open the connection tool. I use MobaXterm_Persona...
Today I made a Spring Festival gold coin red enve...
Content 1. Give readers a reason to stay. Make the...
Preface It is said that if the people doing opera...
In the previous article, I wrote a cross-table up...
The implementation method is divided into three s...
1. Connect to MYSQL Format: mysql -h host address...