Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Docker wait command

Docker wait command

Docker Command ReferenceDocker Command Reference


docker wait The command is used to block until a specified container stops running, and then return the container's exit code.

docker wait The command is very useful for automation scripts, because it can wait for a container to finish a task and then take follow-up actions based on the container's exit status.

Syntax

docker wait [OPTIONS] CONTAINER [CONTAINER...]

Wait for a container to stop and get its exit code:



docker wait my_container

Wait for multiple containers to stop and get their exit codes:



docker wait container1 container2

Example

Start a container that exits immediately:



docker run --name test_container ubuntu bash -c "exit 5"

Use the docker wait command to wait for a container to exit and get its exit code:



docker wait test_container

Output:



5

This command waits for test_container to exit and returns exit code 5.

Start multiple containers that exit immediately:



docker run --name test_container1 ubuntu bash -c "exit 1"

docker run --name test_container2 ubuntu bash -c "exit 2"

Use the docker wait command to wait for multiple containers to exit and get their exit codes:



docker wait test_container1 test_container2

Output:

1

2

This command waits for test_container1 and test_container2 to exit and returns their exit codes 1 and 2.

Notes

docker wait The command is a simple but very useful tool that allows users to wait for a container to stop and get its exit code. With it, users can easily implement task synchronization and automation in scripts. Using docker wait the command, you can ensure that no further operations take place before the specified container has completed its task.


Docker Command ReferenceDocker Command Reference