Debug School

Nilesh Kumar
Nilesh Kumar

Posted on

Docker Wait

When we run docker wait command from the command line with multiple containers( docker wait containerid1 containerid2 ), it holds or blocks the terminal and continuously checks for the container status and outputs the status code once the container stops. However, if we have specified multiple containers, then it checks one by one, which means it will only check the status of the first container then only go to the next one, even if the second container stops before the first container.

Example of Docker wait
Let’s understand the working of the ‘docker wait’ command with the below examples: –

Scenario: – Simple test the command on the terminal.

  1. Create a few containers as below:

docker run -d --name con2 nginx
docker run -d --name con3 redis
docker run -d --name con1 ubuntu sleep 60
docker ps

  1. Now, run the ‘docker wait’ command to understand how it works. Run the below command:

docker wait con3 con1 con2

Explanation: – In the above example, We have put the con3 in the first place because this container is going to stop automatically, and we get the status code and cursor start blinking again –

  1. It will be like this until the other two containers stop working. So, open a new terminal and stop the remaining containers.

docker stop con1
docker stop con2

  1. Now, if we go back and check the terminal where the ‘docker wait’ command was running, we can see that we get the prompt : –

docker wait con3 con1 con2

Top comments (0)