Docker CLI Management: Essential Command-Line Operations Quiz

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.

  1. Starting a Detached Container

    Which Docker CLI command enables you to run a container in detached mode from an existing image called 'webapp'?

    1. docker run -d webapp
    2. docker start webapp -d
    3. docker launch webapp --detach
    4. docker up -d 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.

  2. Listing Containers With Their Status

    To display all containers (including stopped ones) along with their current status, which Docker CLI command should you use?

    1. docker ps -a
    2. docker list all
    3. docker containers --all
    4. docker show -s

    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.

  3. Stopping a Running Container

    If you want to stop a running container named 'db_server', which Docker command should you execute?

    1. docker stop db_server
    2. docker shutdown db_server
    3. docker halt db_server
    4. docker terminate db_server

    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.

  4. Removing an Image From Local Storage

    You wish to remove a local Docker image named 'old_image'. Which command accomplishes this task?

    1. docker rmi old_image
    2. docker delete old_image
    3. docker remove-image old_image
    4. docker erase old_image

    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.

  5. Viewing Live Container Logs

    What is the correct Docker command to continuously view live output logs from a running container named 'backend'?

    1. docker logs -f backend
    2. docker view-log backend
    3. docker console backend -l
    4. docker logs backend -r

    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.