Docker Compose healthcheck
2021-09-09
The most important thing when running integration test using docker-compose is ensured that one container is started completely before others.
Sometime wait-for-it is not enough:
1 cassandra: 2 image: bitnami/cassandra:latest 3 ports: 4 - '7000:7000' 5 - '9042:9042' 6 volumes: 7 - /path/to/init-scripts:/docker-entrypoint-initdb.d 8 9 wait-for-cassandra: 10 image: willwill/wait-for-it 11 command: cassandra:9042 -t 60 12 depends_on: 13 - cassandra:
condition form of depends_on in docker-compose version 3
2021-03-05
As version 3 no longer supports the condition
form of depends_on
, what is the alternative way to wait for a container to be started completely?
From 1.27.0, 2.x and 3.x are merged with COMPOSE_SPEC schema.
version is now optional. So, you can just remove it and specify a condition as before:
1services: 2 web: 3 build: . 4 depends_on: 5 redis: 6 condition: service_healthy 7 redis: 8 image: redis 9 healthcheck: 10 test: ["CMD", "redis-cli", "ping"] 11 interval: 1s 12 timeout: 3s 13 retries: 30