How can you stop a running Docker container?

Prepare for the Docker Certified Associate test with our comprehensive quizzes that include key questions and detailed explanations. Ace your certification!

To stop a running Docker container, the command designed specifically for this purpose is "docker stop [container_id]." This command sends a SIGTERM signal to the main process inside the container, allowing it to terminate gracefully. If the container does not stop within a designated timeout period (default is 10 seconds), Docker then sends a SIGKILL signal to forcibly stop the container.

The ability to allow the main process to exit cleanly is important for applications that need to close files, release resources, or finish ongoing operations. Therefore, using "docker stop" is the preferred method for stopping containers whenever possible, as it prioritizes the proper shutdown of applications within the container over a possibly abrupt termination.

In contrast, while "docker kill [container_id]" also stops a running container, it does so by sending a SIGKILL signal immediately, which forces the container to stop without allowing it to clean up. The command "docker halt [container_id]" is not a valid Docker command, which further clarifies that "docker stop" is indeed the correct approach. Lastly, "docker end [container_id]" is also not a recognized command in the Docker CLI, making it an invalid choice as well.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy