Which command can be used to stop a running container?

Prepare for the Docker Foundations Test. Review essential Docker concepts with multiple choice questions, each with hints and explanations. Ace your exam!

Multiple Choice

Which command can be used to stop a running container?

Explanation:
The command "docker stop [container_id]" is designed specifically to stop a running container in a graceful manner. When invoked, it sends a SIGTERM signal to the main process running inside the container, allowing it to shut down cleanly and finish any ongoing tasks. After a default timeout period (which can be adjusted), if the container does not stop, Docker then sends a SIGKILL signal to forcibly terminate the container if necessary. In contrast, other commands serve different purposes. For instance, while "docker kill [container_id]" also stops a container, it does so immediately by sending a SIGKILL signal without waiting for the container to shut down gracefully. "docker halt [container_id]" is not a valid command within Docker's CLI for managing containers. "docker pause [container_id]" is used to pause a running container, temporarily suspending all processes in that container rather than stopping it altogether. Given this context, the command that best fits the requirement to stop a running container, allowing for a clean shutdown, is "docker stop [container_id]."

The command "docker stop [container_id]" is designed specifically to stop a running container in a graceful manner. When invoked, it sends a SIGTERM signal to the main process running inside the container, allowing it to shut down cleanly and finish any ongoing tasks. After a default timeout period (which can be adjusted), if the container does not stop, Docker then sends a SIGKILL signal to forcibly terminate the container if necessary.

In contrast, other commands serve different purposes. For instance, while "docker kill [container_id]" also stops a container, it does so immediately by sending a SIGKILL signal without waiting for the container to shut down gracefully. "docker halt [container_id]" is not a valid command within Docker's CLI for managing containers. "docker pause [container_id]" is used to pause a running container, temporarily suspending all processes in that container rather than stopping it altogether.

Given this context, the command that best fits the requirement to stop a running container, allowing for a clean shutdown, is "docker stop [container_id]."

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy