数据库初始化慢导致,微服务docker启动模式,gateway和前端无法访问实例接口(网关轮询nacos就绪再启动、暴露nacos控制台18080、前端nginx动态DNS解析)

This commit is contained in:
JEECG 2026-07-09 14:05:33 +08:00
parent 56461aa3f4
commit 1cd59161a1
2 changed files with 19 additions and 1 deletions

View File

@ -48,6 +48,7 @@ services:
context: ./jeecg-boot/jeecg-server-cloud/jeecg-cloud-nacos
ports:
- 8848:8848
- 18080:18080
container_name: jeecg-boot-nacos
depends_on:
- jeecg-boot-mysql
@ -93,6 +94,19 @@ services:
- jeecg-boot-system
container_name: jeecg-boot-gateway
hostname: jeecg-boot-gateway
# 首次启动关键主动轮询nacos直到 jeecg-system 注册为健康实例再启动网关,
# 避免网关先于system注册而拿到空路由swagger空、前端调不到后台需手动重启网关
# 注意Nacos 3.x 已移除 v1/v2 open-api实例查询需使用 v3 admin 接口
command:
- sh
- -c
- |
echo 'waiting for jeecg-system to register in nacos...';
until curl -s 'http://jeecg-boot-nacos:8848/nacos/v3/admin/ns/instance/list?serviceName=jeecg-system&groupName=DEFAULT_GROUP' | grep -q '"healthy":true'; do
sleep 5;
done;
echo 'jeecg-system is registered, starting gateway.';
exec java -Djava.security.egd=file:/dev/./urandom -jar jeecg-cloud-gateway-3.9.3.jar
networks:
- jeecg-boot

View File

@ -4,8 +4,12 @@ VOLUME /tmp
ENV LANG en_US.UTF-8
RUN echo "server { \
listen 80; \
#使用docker内嵌DNS运行时解析避免gateway容器重启换IP后nginx缓存旧IP导致502 \
resolver 127.0.0.11 valid=10s ipv6=off; \
location /jeecgboot/ { \
proxy_pass http://jeecg-boot-gateway:9999/; \
set \$jeecg_gateway jeecg-boot-gateway; \
rewrite ^/jeecgboot/?(.*)\$ /\$1 break; \
proxy_pass http://\$jeecg_gateway:9999; \
proxy_redirect off; \
proxy_set_header Host jeecg-boot-system; \
proxy_set_header X-Real-IP \$remote_addr; \