[docker-compose] Application failed to connect to Nacos server: "nacos:8848"
geekyouth opened this issue · 0 comments
geekyouth commented
docker-compose-dev.yml
version: "3.8"
networks:
ruoyi-cloud-dev:
name: ruoyi-cloud-dev
services:
mysql57:
image: mysql:5.7.37
hostname: mysql57
container_name: ruoyi-mysql57-dev
restart: unless-stopped
ports:
- "23306:3306"
volumes:
- ./mysql/sql/00.reset-password.sql:/tmp/00.reset-password.sql
- ./mysql/sql/01.init-all-db-user.dev.sql:/docker-entrypoint-initdb.d/01.init-all-db-user.dev.sql
- ./mysql/sql/02.nacos211-mysql-default.sql:/docker-entrypoint-initdb.d/02.nacos211-mysql-default.sql
- ./mysql/sql/03.ruoyi_nacos_config.dev.sql:/docker-entrypoint-initdb.d/03.ruoyi_nacos_config.dev.sql
- ./mysql/sql/04.ruoyi_cloud.sql:/tmp/04.ruoyi_cloud.sql
- ./mysql/sql/04.ruoyi_cloud_import.dev.sql:/docker-entrypoint-initdb.d/04.ruoyi_cloud_import.dev.sql
- ./_docker-data/dev/mysql-data/:/var/lib/mysql/
- ./_docker-data/dev/mysql-log/:/var/log/mysql/
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: dev-mysql57-pass
MYSQL_USER: demo
MYSQL_PASSWORD: demo
MYSQL_DATABASE: demo
command: [
'mysqld',
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci',
'--default-time-zone=+8:00',
'--lower-case-table-names=1'
]
healthcheck:
test: [ "CMD-SHELL", "mysql -e 'select 1 from nacos_config.users' -unacos_config -pnacos_config" ]
interval: 10s
timeout: 2s
retries: 10
start_period: 10s
networks:
ruoyi-cloud-dev:
redis:
image: redis/redis-stack:6.2.6-v7
hostname: redis
container_name: ruoyi-redis-dev
restart: unless-stopped
ports:
- "26379:6379"
- "28001:8001"
environment:
TZ: Asia/Shanghai
REDIS_ARGS: "--requirepass redis_pass"
healthcheck:
test: [ "CMD-SHELL", "redis-cli ping" ]
interval: 10s
timeout: 2s
retries: 10
start_period: 3s
networks:
ruoyi-cloud-dev:
sentinel:
image: sentinel:dev-1.6.3
hostname: sentinel
container_name: ruoyi-sentinel-dev
environment:
TZ: Asia/Shanghai
JAVA_OPTS: "-Dserver.port=8718 -Dcsp.sentinel.dashboard.server=localhost:8718 -Dsentinel.dashboard.auth.username=sentinel -Dsentinel.dashboard.auth.password=sentinel -Djava.security.egd=file:/dev/./urandom -Dcsp.sentinel.api.port=8719"
ports:
- "28718:8718"
- "28719:8719"
restart: unless-stopped
volumes:
- ./_docker-data/dev/sentinel-logs/:/root/logs
healthcheck:
test: [ "CMD-SHELL", "curl -f http://localhost:8718" ]
interval: 10s
timeout: 2s
retries: 10
start_period: 3s
networks:
ruoyi-cloud-dev:
# WEB 服务
nacos:
image: nacos/nacos-server:v2.1.1
hostname: nacos
container_name: ruoyi-nacos-dev
restart: unless-stopped
environment:
TZ: Asia/Shanghai
PREFER_HOST_MODE: hostname
# PREFER_HOST_MODE: ip
MODE: standalone
SPRING_DATASOURCE_PLATFORM: mysql
MYSQL_SERVICE_HOST: mysql57
MYSQL_SERVICE_PORT: 3306
MYSQL_SERVICE_DB_NAME: nacos_config
MYSQL_SERVICE_USER: nacos_config
MYSQL_SERVICE_PASSWORD: nacos_config
MYSQL_SERVICE_DB_PARAM: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai
volumes:
- ./_docker-data/dev/nacos-logs/:/home/nacos/logs/
ports:
- "28848:8848"
- "29848:9848"
- "29555:9555"
depends_on:
mysql57:
condition: service_healthy
healthcheck:
test: [ "CMD-SHELL", "curl -f http://localhost:8848/nacos" ]
timeout: 2s
interval: 10s
retries: 5
start_period: 30s
networks:
ruoyi-cloud-dev:
# 首次 up 可能提示连不上 localhost:6379,重启本服务即可
ruoyi-gateway:
build:
context: .
dockerfile: ruoyi-gateway/Dockerfile
image: ruoyi-gateway:dev-v0.6.0-20230819
hostname: gateway
container_name: ruoyi-gateway-dev
restart: unless-stopped
ports:
- "28080:8080"
environment:
ARGS: "--spring.profiles.active=dev"
JAVA_OPTS: "-Xms128m -Xmx128m -Djava.security.egd=file:/dev/./urandom"
volumes:
- ./_docker-data/dev/ruoyi-gateway-logs/:/opt/logs/
depends_on:
nacos:
condition: service_healthy
sentinel:
condition: service_healthy
redis:
condition: service_started
healthcheck: # TODO BUG
test: [ "CMD-SHELL", "curl -f localhost:8080/doc.html" ]
interval: 10s
timeout: 5s
retries: 10
start_period: 15s
networks:
ruoyi-cloud-dev:
docker compose -f docker-compose-dev.yml up -d mysql57 redis sentinel
....
等待 mysql 导入 sql 完毕
docker compose -f docker-compose-dev.yml up -d nacos
...
docker compose -f docker-compose-dev.yml up -d ruoyi-gateway
然后 gateway 报错:
Application failed to connect to Nacos server: "nacos:8848"
但是 从宿主机上的浏览器打开映射出来的 28848:8848 ---> 127.0.0.1:28848/nacos 是可以访问的