在前面的一篇文章中提到了JEECG的Alpine鏡像使用時出現的問題,就是驗證碼需要使用到fontmanager,而環境中的OPENJDK的JRE中又沒有提供,所以退而求其次使用官方的Dockerfile中的CentOS的方式安裝JDK來完成,通過驗證發現提供openjdk8-jre、 fontconfig和ttf-dejavu就可以解決此問題。
Dockerfile
FROM nginx:1.18-alpine
MAINTAINER liumiao [email protected]
RUN apk update \
&& apk --no-cache add openjdk8-jre fontconfig ttf-dejavu \
&& 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 ;
}
構建
構建命令示例:docker build -t liumiaocn/jeecg:alpine-2.2.0 -f Dockerfile.alpine .
注:另外請自行編譯前端後端,提供相應的jar和dist目錄即可構建。另外構建的鏡像已上傳至Dockerhub,可自行獲取,使用時請注意使用自己的Jar替換,因爲Jar中的Redis和MySQL的配置是硬編碼的方式存在的。
部署和啓動步驟
部署和啓動步驟和前文整理的CentOS方式沒有任何不同,詳細可參看:
唯一的區別在於使用的鏡像名稱不同:
啓動示例命令:docker run --name=jeecg -d -p 8080:8080 -p 8088:80 liumiaocn/jeecg:alpine-2.2.0
結果確認
liumiaocn:jeecg liumiao$ docker ps |grep alpine
380a555d4df9 liumiaocn/jeecg:alpine-2.2.0 "/bin/sh -c '/bin/sh…" 35 minutes ago Up 35 minutes 0.0.0.0:8080->8080/tcp, 0.0.0.0:8088->80/tcp jeecg
liumiaocn:jeecg liumiao$