Explore key operations for managing Docker containers and images using the command line. This quiz assesses your understanding of fundamental Docker CLI concepts, syntax, and best practices for efficient container management within popular tool ecosystems.
Which Docker CLI command enables you to run a container in detached mode from an existing image called 'webapp'?
Explanation: The correct answer is 'docker run -d webapp' because the '-d' flag tells Docker to run the container in detached mode, allowing it to run in the background. 'docker start webapp -d' is incorrect since the 'start' command lacks the '-d' option. 'docker launch webapp --detach' uses the wrong command and flag syntax. 'docker up -d webapp' is an invalid command in the Docker CLI.
To display all containers (including stopped ones) along with their current status, which Docker CLI command should you use?
Explanation: 'docker ps -a' is correct because 'ps' lists containers and the '-a' flag ensures both running and stopped containers are displayed. 'docker list all' is not a valid Docker CLI command. 'docker containers --all' is not recognized syntax in this context. 'docker show -s' is unrelated and does not provide container status information.
If you want to stop a running container named 'db_server', which Docker command should you execute?
Explanation: The correct command is 'docker stop db_server'; 'stop' is the proper instruction to halt a running container. 'docker shutdown db_server' is invalid as 'shutdown' is not a recognized Docker command. Similarly, 'halt' and 'terminate' may sound logical but are not actual Docker container commands. Only 'stop' will successfully halt the container process.
You wish to remove a local Docker image named 'old_image'. Which command accomplishes this task?
Explanation: 'docker rmi old_image' is the correct syntax; 'rmi' stands for 'remove image.' The 'delete', 'remove-image', and 'erase' commands are either incorrect or do not exist in the official Docker command-line interface for removing images. Only 'rmi' will successfully remove the image from local storage.
What is the correct Docker command to continuously view live output logs from a running container named 'backend'?
Explanation: The correct choice is 'docker logs -f backend', where '-f' stands for 'follow', enabling live log streaming. 'docker view-log backend' and 'docker console backend -l' may sound plausible but are not authentic Docker commands. 'docker logs backend -r' uses an incorrect flag, as '-r' is not a valid option in this context.