解决docker alpine缺少字体的问题 Could not initialize class sun.awt.X11FontManager
制作的springboot项目镜像,缺少字体报错Could not initialize class sun.awt.X11FontManager
原因镜像中缺少字体
解决:
制作镜像时,添加字体库,Dockerfile文件
中添加如下内容
注意: jdk版本一定要使用,Eclipse Temurin 项目提供的 OpenJDK 17 开发工具包(JDK)。(或者是jdk8)
Docker 镜像,基于 Alpine Linux 轻量级操作系统。
- 配置了清华源下载也不慢
FROM eclipse-temurin:17-jdk-alpine# 配置清华源 + 更新索引
RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/main" > /etc/apk/repositories && \echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/community" >> /etc/apk/repositories && \apk update# 安装依赖
RUN apk add --no-cache freetype fontconfig# 设置环境变量为 UTF-8 编码
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' > /etc/timezone#############一定要安装字体,要不然验证码报错#########################.....其他配置