這篇文章memo一下JEECG部署時使用Alpine鏡像會產生的問題。
Dockerfile
FROM nginx:1.18-alpine
MAINTAINER liumiao [email protected]
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.sh
default.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 [email protected]
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的問題,後續有時間會繼續確認。