ci(docker): 更新docker-compose配置和容器版本

- 升级consul和traefik到新版本
- 为服务添加健康检查和环境变量配置
- 统一容器命名规范为ari-前缀
- 修改端口暴露方式和重启策略
- 添加whoami服务用于测试
This commit is contained in:
fanfpy 2025-07-17 11:35:35 +08:00
parent f12448c7d8
commit 9f37b523bd

View File

@ -6,105 +6,126 @@ networks:
services: services:
consul: consul:
image: consul:1.11.4 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 command: "consul agent -server -bootstrap-expect=1 ${CONSUL_DEV_MODE} -config-dir=/consul/config -client=0.0.0.0"
ports: ports:
- "8500:8500" - "8500:8500"
- "8600:8600/udp" - "8600:8600/udp"
volumes: volumes:
- ./consul/config:/consul/config - ./consul/config/${ENV_CONFIG_DIR}:/consul/config
environment: environment:
- CONSUL_DEV_MODE=-dev - CONSUL_DEV_MODE=-dev
networks: networks:
- microservice-network - microservice-network
restart: unless-stopped healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8500/v1/status/leader"]
interval: 10s
timeout: 5s
retries: 3
restart: always
traefik: traefik:
image: traefik:v2.9 image: traefik:v2.11
container_name: ari-traefik container_name: ari-traefik
command: command:
- "--providers.consulcatalog=true" - --configFile=/etc/traefik/traefik.yml
- "--providers.consulcatalog.endpoint.address=ari-consul:8500"
- "--providers.consulcatalog.service.name=traefik"
- "--api.dashboard=true"
- "--log.level=INFO"
ports: ports:
- "80:80" - "80:80"
- "443:443" - "443:443"
- "8080:8080" - "8080:8080"
volumes: volumes:
- ./traefik/certs:/etc/traefik/certs - ./traefik/certs:/etc/traefik/certs
- ./traefik/config:/etc/traefik/config - ./traefik/config/${TRAEFIK_CONFIG_DIR}/traefik.yml:/etc/traefik/traefik.yml
- /var/run/docker.sock:/var/run/docker.sock:ro - /var/run/docker.sock:/var/run/docker.sock
depends_on: depends_on: []
- consul
networks: networks:
- microservice-network - microservice-network
restart: unless-stopped restart: always
data-service: data-service:
image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/data-service:latest image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/data-service:latest
container_name: data-service container_name: ari-data-service
ports: expose:
- "8001:80" - "8000"
environment:
- SERVICE_NAME=data-service
networks: networks:
- microservice-network - microservice-network
depends_on: depends_on:
- consul - data-service
restart: unless-stopped - quant-service
- emotion-service
- recommend-service
- user-service
restart: always
emotion-service: emotion-service:
image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/emotion-service:latest image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/emotion-service:latest
container_name: emotion-service container_name: ari-emotion-service
ports: expose:
- "8002:80" - "8002"
environment:
- SERVICE_NAME=emotion-service
networks: networks:
- microservice-network - microservice-network
depends_on: depends_on:
- consul - consul
restart: unless-stopped restart: always
frontend: frontend:
image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/frontend:latest image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/frontend:latest
container_name: frontend container_name: ari-frontend
ports: expose:
- "8000:80" - "80"
environment:
- SERVICE_NAME=frontend
networks: networks:
- microservice-network - microservice-network
depends_on: depends_on:
- consul - consul
restart: unless-stopped restart: always
quant-service: quant-service:
image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/quant-service:latest image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/quant-service:latest
container_name: quant-service container_name: ari-quant-service
ports: expose:
- "8005:80" - "8001"
environment:
- SERVICE_NAME=quant-service
networks: networks:
- microservice-network - microservice-network
depends_on: depends_on:
- consul - consul
restart: unless-stopped restart: always
recommend-service: recommend-service:
image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/recommend-service:latest image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/recommend-service:latest
container_name: recommend-service container_name: ari-recommend-service
ports: expose:
- "8003:80" - "8003"
environment:
- SERVICE_NAME=recommend-service
networks: networks:
- microservice-network - microservice-network
depends_on: depends_on:
- consul - consul
restart: unless-stopped restart: always
user-service: user-service:
image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/user-service:latest image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/user-service:latest
container_name: user-service container_name: ari-user-service
ports: expose:
- "8004:80" - "8004"
environment:
- SERVICE_NAME=user-service
networks:
- microservice-network
depends_on: []
restart: always
whoami:
image: traefik/whoami
container_name: whoami
networks: networks:
- microservice-network - microservice-network
depends_on:
- consul
restart: unless-stopped