

With the docker run commands -stop-signal flag, you can specify the stop signal when starting the container. Instead, you can instruct Docker to use alternative stop signals. But you may not want the default behavior. You learned about Docker’s default behavior (stop signal), with the docker stop containers command, when stopping a container. Stopping a Container Using Process Signals When using the SIGTERM signal, Docker uses the signal to gracefully stop a process by waiting for a default 10 seconds before sending the SIGKILL signal, which terminates the process immediately. Linux signals inform a process of an event, but it is up to the process to decide how to act on a given signal. The docker stop containers command uses the SIGTERM signal. A sub-expression instructs the shell to process one set of commands, docker ps -q, first and then return the set of results to the original command docker stop. The $(docker ps -q) construct above is a sub-expression in both Bash on Linux and PowerShell on Windows. Stopping multiple Docker containers at once. As shown in the example below, stop the container with the docker stop containers command. Let’s get started with the first command: the docker stop containers command and how it accomplishes stopping containers.įor example, perhaps you need to stop a running container with the name mystifying_hofstadter and an ID of fb66ed502096. Related: How to Install and Use Docker on Ubuntu (In the Real World) Ending Containers with the docker stop Containers Command



