YouTip LogoYouTip

Docker Wait Command

# Docker wait Command [![Image 3: Docker Command Manual](#)Docker Command Manual](#) * * * The `docker wait` command is used to block until the specified container stops running, and then returns the container's exit code. The `docker wait` command is very useful for automation scripts, as it can wait for a container to complete a task and then take subsequent actions based on the container's exit status. ### Syntax docker wait 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 the container to exit and get the exit code: docker wait test_container Output: 5 This command waits for test_container to exit and returns the 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: 12 This command waits for test_container1 and test_container2 to exit and returns their exit codes 1 and 2. ### Notes * The `docker wait` command blocks until the container stops, so use caution when using it on long-running containers. * This command only returns the container's exit code and does not provide any other information about the container's status or output. The `docker wait` 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. Using the `docker wait` command ensures that no subsequent actions are taken until the specified container has completed its task. * * Docker Command Manual](#)
← Prop Element ClientwidthProp Element Clientleft β†’