Docker wait command

Docker command reference


docker waitThe command blocks until the specified container stops running, then returns the container's exit code.

docker waitThe command is very useful for automation scripts because it can wait for a container to complete a task and take subsequent 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 waitThe command blocks until the container stops, so use caution when working with long-running containers.
  • This command only returns the container's exit code and provides no other information about the container's status or output.

docker waitThe command is a simple but very useful tool that allows users to wait for a container to stop and get its exit code. With this command, users can easily implement task synchronization and automation in scripts. Usedocker waitThe command ensures that no subsequent operations are performed until the specified container completes its task.


Docker command reference

other extensions