How to stop all containers when one container stops with docker-compose?

前端 未结 4 1288
不知归路
不知归路 2020-12-13 17:09

Up until recently, when one was doing docker-compose up for a bunch of containers and one of the started containers stopped, all of the containers were stopped.

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 17:42

    In your docker compose file, setup your test driver container to depend on other containers (with depends_on parameter). Your docker compose file should look like this:

    services:
      application_server:
         ...
      selenium:
         ...
      test_driver:
        entry_point: YOUR_TEST_COMMAND
        depends_on:
          - application_server
          - selenium
    

    With dependencies expressed this way, run:

    docker-compose run test_driver
    

    and all the other containers will shut down when the test_driver container is finished.



    This solution is an alternative to the docker-compose up --abort-on-container-exit answer. The latter will also shut down all other containers if any of them exits (not only the test driver). It depends on your use case which one is more adequate.

提交回复
热议问题