What command is used to stop all running containers?

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

The command "docker stop $(docker ps -q)" is correct because it effectively stops all running containers by combining two commands.

Firstly, "docker ps -q" lists all currently running containers but only returns their container IDs, not any other information. The "-q" flag stands for "quiet" mode, which means that only the container IDs will be shown.

Then, the output of this command, which is a list of container IDs, is piped into the "docker stop" command. The "docker stop" command takes one or more container IDs as arguments and stops those containers gracefully. Therefore, when executed together, this command line will stop all containers that are currently running.

This method is preferred for stopping multiple containers at once compared to alternatives, which do not correctly reference the mechanics of Docker commands for managing container states.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy