1.背景
在本地部署没有问题,但是通过docker-compose部署到docker环境中就出现以下异常:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager
或
com.alibaba.excel.exception.ExcelGenerateException: java.lang.UnsatisfiedLinkError: /usr/local/jdk-11.0.11/lib/libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory
经过排查是由于docker环境中缺少字体文件造成的
修改dockerfile,增加以下配置:
COPY dejavu /usr/share/fonts
全部dockerfile配置文件如下
FROM harbor.minexiot.com/base/jdk:11.0.11 # 设置环境变量为 UTF-8 编码 ENV LANG C.UTF-8 ENV LC_ALL C.UTF-8 ARG JAR_PATH=./ ARG APP_NAME=svc-icp ENV JAVA_OPTS "" ENV NACOS_SERVER_ADRESS "nacos" ENV NACOS_CONFIG_NAMESPACE "docker" WORKDIR /services COPY "${JAR_PATH}${APP_NAME}.jar" "/services/${APP_NAME}.jar" COPY run.sh /services #COPY wind /usr/share/fonts/ #RUN fc-cache -fv RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN echo 'Asia/Shanghai' > /etc/timezone RUN apt update RUN apt install fontconfig -y COPY dejavu /usr/share/fonts EXPOSE 8080 5004 CMD ["sh", "run.sh"]
标签:RUN,springboot,libfreetype,X11FontManager,usr,ENV,share,docker,COPY From: https://www.cnblogs.com/guanxiaohe/p/18599608