我有一个包含 3 个服务的 docker-compose:config-server、cpo-events 和 cpo-executor。我希望服务仅在 config-server 准备好时启动,因为服务需要 config-server 服务中的配置文件。
码头工人-compose.yml:
version: '3.7'
services:
config-server:
container_name: cup-config-server
image: cup-config-server:1.0.0
expose:
- 8888
ports:
- 8888:8888
networks:
- spring-cloud-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8888/cpo-executor/dev"]
interval: 30s
timeout: 10s
retries: 5
cpo-events:
container_name: cpo-events-kafka
image: cpo-events-kafka:1.0.0
expose:
- 8878
ports:
- 8878:8878
networks:
- spring-cloud-network
depends_on:
- config-server
links:
- config-server
cpo-executor:
container_name: cpo-executor
image: cpo-executor:1.0.0
expose:
- 8879
ports:
- 8879:8879
networks:
- spring-cloud-network
depends_on:
- config-server
links:
- config-server
networks:
spring-cloud-network:
driver: bridge
Depends_on、links、healthcheck,没有什么能保证这两个服务(cpo-executor、cpo-event)只有在 config-server 准备好后才能启动。