这篇文章memo一下JEECG部署时使用Alpine镜像会产生的问题。
DockerfileFROM nginx:1.18-alpine MAINTAINER liumiao liumiaocn@outlook.com RUN apk update \ && apk add openjdk8-jre-base \ && touch /etc/init.d/start.sh \ && chmod +x /etc/init.d/start.sh \ && echo "#!/bin/sh " >> /etc/init.d/start.sh \ && echo "/usr/sbin/nginx -c /etc/nginx/nginx.conf" >> /etc/init.d/start.sh \ && echo " java -jar /jeecgboot.jar " >> /etc/init.d/start.sh ADD jeecg-boot-module-system-2.2.0.jar jeecgboot.jar ADD dist/ /usr/share/nginx/html/ ADD default.conf /etc/nginx/conf.d/default.conf EXPOSE 80 8080 ENTRYPOINT /bin/sh -c /etc/init.d/start.shdefault.conf
server { listen 80; location ^~ /jeecg-boot { proxy_pass http://127.0.0.1:8080/jeecg-boot/; proxy_set_header Host 127.0.0.1; proxy_set_header X-Real-IP \$remote_addr; proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; } location / { root /usr/share/nginx/html/; index index.html index.htm; if (!-e \$request_filename) { rewrite ^(.*)\$ /index.html?s=\$1 last; break; } } access_log /var/log/nginx/access.log ; }启动后的问题
看一下NoClassDefFound的类名为sun.awt,大概率是使用Oracle的JDK能够解决问题,而由于Oracle的JDK是基于GLIBC的,所以Alpine只好先扔下了。这也大概是JEECG的源码里面有一个很粗糙的Dockerfile是基于CentOS7的原因。所以直接修正一下将Dockerfile改为基于CentOS方式的即解决了问题。详细如下所示:
[root@liumiaocn jeecg]# cat Dockerfile FROM centos:7 MAINTAINER liumiao liumiaocn@outlook.com RUN cd /etc/yum.repos.d/ \ && yum -y install wget \ && wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo \ && yum clean all \ && yum makecache \ && yum update -y \ && yum -y install nginx \ && yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel \ && touch /etc/init.d/start.sh \ && touch jeecgboot.log \ && chmod +x /etc/init.d/start.sh \ && echo "#!/bin/bash " >> /etc/init.d/start.sh \ && echo "/usr/sbin/nginx -c /etc/nginx/nginx.conf" >> /etc/init.d/start.sh \ && echo " java -jar /jeecgboot.jar " >> /etc/init.d/start.sh \ && mkdir -p /var/www/html ADD nginx.conf /etc/nginx/nginx.conf ADD dist/ /var/www/html/ ADD jeecg-boot-module-system-2.2.0.jar jeecgboot.jar EXPOSE 80 8080 ENTRYPOINT /bin/sh -c /etc/init.d/start.sh [root@liumiaocn jeecg]# cat nginx.conf # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. server { listen 80; location ^~ /jeecg-boot { proxy_pass http://127.0.0.1:8080/jeecg-boot/; proxy_set_header Host 127.0.0.1; proxy_set_header X-Real-IP \$remote_addr; proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; } location / { root /var/www/html/; index index.html index.htm; if (!-e \$request_filename) { rewrite ^(.*)\$ /index.html?s=\$1 last; break; } } access_log /var/log/nginx/access.log ; } # Settings for a TLS enabled server. # # server { # listen 443 ssl http2 default_server; # listen [::]:443 ssl http2 default_server; # server_name _; # root /usr/share/nginx/html; # # ssl_certificate "/etc/pki/nginx/server.crt"; # ssl_certificate_key "/etc/pki/nginx/private/server.key"; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 10m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # location / { # } # # error_page 404 /404.html; # location = /40x.html { # } # # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # } } [root@liumiaocn jeecg]#备注
似乎通过安装apk add ttf-dejavu能够解决Font的问题,后续有时间会继续确认。