简体   繁体   中英

How to start Docker container only after another container is exited

Let's suppose I have 2 containers: composer and php , which share the same code base, ie the same volume. And I want to manage them with a single docker-compose command like docker-compose up .

So the question is How can I start these containers one by one, not at the same time? I mean, start my php container only after composer one is exited, ie composer container should install all vendors for my php container and exit, then and only then php container should start a built-in PHP web server with already installed vendors.

PS Now I get the behavior that both containers start at the same time. So my php container is trying to start web server without vendors, while composer container is trying to install these vendors.

Is there a good solution for this case?

There are couple of things can help you;

  • depends_on: it does not wait for another service to finish, it only waits until the other services starts. see: depends_on
  • health_check: it does not start the service until the command returns success. see: healthcheck
  • create a shell script to order of initialisation of your containers/services. see: startup order

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM