I've read lots for similar topics; For example this: Docker Compose wait for container X before starting Y etc.
So, I'm trying to implement a wait for only using compose and health checks.
I have only one docker-compose file. There is a section for the app and for test for this app.
Test (service) can be executed only when app(jar, db etc) will be ready. Also after test (service) execution, I want to get status for this execution via $?
So my compose file is next:
version: "2.1"
networks:
myNetwork:
services:
rabbitmq:
...
networks:
- myNetwork
healthcheck:
test: ["CMD", "rabbitmqctl", "status"]
interval: 100s
timeout: 10s
retries: 10
app:
...
depends_on:
rabbitmq:
condition: service_healthy
networks:
- myNetwork
healthcheck:
test: ["CMD", "wget", "http://localhost:8080/ping"]
interval: 100s
timeout: 10s
retries: 10
tests:
build:
context: .
dockerfile: TestDocker
depends_on:
app:
condition: service_healthy
networks:
- myNetwork
Im trying to run:
docker-compose up -d app && docker-compose run tests;
or
docker-compose run tests
But docker-compose run tests
don't waits for condition: service_healthy; (app and rabbitmq containers is started but service_healthy was not checked);
And this is the problem.
When I do something like this:
docker-compose up -d app && sleep 20 && docker-compose run tests;
So is there is any possibility to do sleep or wait for, for command: docker-compose run tests
?