Search code examples
dockerdocker-composeend-to-end

How to make docker-compose stop after X containers have stopped?


I have a docker-compose.yml file that spins up 11 containers:

  • 1 container runs a web application that I want to test
  • 10 near identical containers run a bunch of end to end tests that target the first container

Only after all 10 test containers have finished running all their tests, I'd like docker-compose to spin down all 11 containers.

Does docker-compose up support this sort of functionality or do I need to build my own on top of it?


Solution

  • If you have 11 containers (let's say they are called a_1, a_2, ... ,a_11) and you need to wait for 10 of them (let's say the first 10) then you can do the following using the command docker wait:

    docker-compose up -d
    docker wait a_1 a_2 ... a_10
    docker-compose down