refactor(docker): 优化docker-compose配置结构和镜像地址

- 重新组织服务配置结构,使其更清晰易读
- 更新镜像地址为阿里云registry标准格式
- 调整端口映射和健康检查配置
- 规范服务依赖关系声明
This commit is contained in:
fanfpy 2025-07-17 13:09:45 +08:00
parent 49cac43f4f
commit 28e572d700

View File

@ -8,14 +8,13 @@ services:
consul: consul:
image: consul:1.15 image: consul:1.15
container_name: ari-consul container_name: ari-consul
command: "consul agent -server -bootstrap-expect=1 ${CONSUL_DEV_MODE} -config-dir=/consul/config -client=0.0.0.0" restart: always
ports: ports:
- "8500:8500" - "8500:8500" # Consul Web UI
- "8600:8600/udp" - "8600:8600/udp" # DNS服务
volumes: volumes:
- ./consul/config/${ENV_CONFIG_DIR}:/consul/config - ./consul/config/${ENV_CONFIG_DIR}:/consul/config
environment: command: "consul agent -server -bootstrap-expect=1 ${CONSUL_DEV_MODE} -config-dir=/consul/config -client=0.0.0.0"
- CONSUL_DEV_MODE=-dev
networks: networks:
- microservice-network - microservice-network
healthcheck: healthcheck:
@ -23,7 +22,6 @@ services:
interval: 10s interval: 10s
timeout: 5s timeout: 5s
retries: 3 retries: 3
restart: always
traefik: traefik:
image: traefik:v2.11 image: traefik:v2.11
@ -33,99 +31,100 @@ services:
ports: ports:
- "80:80" - "80:80"
- "443:443" - "443:443"
- "8080:8080" - "8080:8080" # Traefik dashboard
volumes: volumes:
- ./traefik/certs:/etc/traefik/certs
- ./traefik/config/${TRAEFIK_CONFIG_DIR}/traefik.yml:/etc/traefik/traefik.yml
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
depends_on: [] - ./traefik/config/${TRAEFIK_CONFIG_DIR}/traefik.yml:/etc/traefik/traefik.yml
- ./traefik/certs:/etc/traefik/certs
networks: networks:
- microservice-network - microservice-network
restart: always
data-service: data-service:
image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/data-service:latest image: registry.cn-hangzhou.aliyuncs.com/testrrr/data-service:latest
container_name: ari-data-service container_name: ari-data-service
expose: restart: always
- "8000" ports:
- "8000:8000"
networks:
- microservice-network
environment: environment:
- SERVICE_NAME=data-service - SERVICE_NAME=data-service
networks:
- microservice-network
depends_on:
- data-service
- quant-service
- emotion-service
- recommend-service
- user-service
restart: always
emotion-service:
image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/emotion-service:latest
container_name: ari-emotion-service
expose:
- "8002"
environment:
- SERVICE_NAME=emotion-service
networks:
- microservice-network
depends_on:
- consul
restart: always
frontend:
image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/frontend:latest
container_name: ari-frontend
expose:
- "80"
environment:
- SERVICE_NAME=frontend
networks:
- microservice-network
depends_on:
- consul
restart: always
quant-service: quant-service:
image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/quant-service:latest image: registry.cn-hangzhou.aliyuncs.com/testrrr/quant-service:latest
container_name: ari-quant-service container_name: ari-quant-service
restart: always
depends_on:
consul:
condition: service_healthy
expose: expose:
- "8001" - "8001"
networks:
- microservice-network
environment: environment:
- SERVICE_NAME=quant-service - SERVICE_NAME=quant-service
emotion-service:
image: registry.cn-hangzhou.aliyuncs.com/testrrr/emotion-service:latest
container_name: ari-emotion-service
restart: always
depends_on:
consul:
condition: service_healthy
expose:
- "8002"
networks: networks:
- microservice-network - microservice-network
depends_on: environment:
- consul - SERVICE_NAME=emotion-service
restart: always
recommend-service: recommend-service:
image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/recommend-service:latest image: registry.cn-hangzhou.aliyuncs.com/testrrr/recommend-service:latest
container_name: ari-recommend-service container_name: ari-recommend-service
restart: always
depends_on:
consul:
condition: service_healthy
expose: expose:
- "8003" - "8003"
environment:
- SERVICE_NAME=recommend-service
networks: networks:
- microservice-network - microservice-network
depends_on: environment:
- consul - SERVICE_NAME=recommend-service
restart: always
user-service: user-service:
image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/user-service:latest image: registry.cn-hangzhou.aliyuncs.com/testrrr/user-service:latest
container_name: ari-user-service container_name: ari-user-service
expose: restart: always
- "8004" depends_on:
environment: consul:
- SERVICE_NAME=user-service condition: service_healthy
networks: expose:
- microservice-network - "8004"
depends_on: [] networks:
restart: always - microservice-network
environment:
- SERVICE_NAME=user-service
frontend:
image: registry.cn-hangzhou.aliyuncs.com/testrrr/frontend:latest
container_name: ari-frontend
restart: always
depends_on:
- data-service
- quant-service
- emotion-service
- recommend-service
- user-service
expose:
- "80"
networks:
- microservice-network
environment:
- SERVICE_NAME=frontend
whoami: whoami:
image: traefik/whoami image: traefik/whoami
container_name: whoami container_name: whoami
networks: networks:
- microservice-network - microservice-network