Let's suppose I have 2 containers: composer
and php
, which share the same code base, i.e. 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, i.e. 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.
P.S. 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?
Dockerfile Command to Keep the Container Running Method 1: You can use the -t (pseudo-tty) docker parameter to keep the container running. Method 2: You can run the container directly passing the tail command via arguments as shown below. Method 3: Another method is to execute a sleep command to infinity.
Alternatively, if the container just exited we can easily start it in a single step. For this, we use the command, Here `docker ps -q -l` replaces the container ID of the last created Docker container. Additionally, we can also use options like -i to start the container in interactive mode.
This means that with the unless-stopped restart policy, if the container was running before the reboot, the container would be restarted once the system restarted. When an application within a Docker container exits, that container will be also halted.
There are couple of things can help you;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With