Mastering Docker for Consistent App Deployment Quiz

Discover how Docker tackles the 'it works on my machine' issue, the differences between containers and images, and key commands for streamlined app delivery. This quiz covers practical concepts, analogies, and best practices from a beginner-friendly Docker guide.

  1. Understanding Environment Drift

    What is the main cause of software behaving differently on different machines?

    1. Slow internet connection
    2. Outdated code syntax
    3. Incorrect programming language
    4. Environment drift

    Explanation: Environment drift means differences in libraries, environment variables, or OS configurations between systems, which leads to unexpected app behavior. Outdated syntax and incorrect language usually cause errors regardless of environment. Slow internet may affect downloads but not core code execution differences.

  2. Analogy for Docker's Solution

    Which analogy best explains how Docker packages applications for consistent results?

    1. Borrowing a friend's cookbook
    2. Sealed cooking pod with all ingredients and tools
    3. Sending only a written recipe
    4. Cooking with random ingredients

    Explanation: Docker packages everything needed, like a sealed pod containing all ingredients and tools. Sending a recipe or using random ingredients leads to inconsistencies. Borrowing a cookbook doesn't ensure the same tools or environment.

  3. Virtual Machines vs. Containers

    Which is a key difference between virtual machines (VMs) and Docker containers?

    1. Containers emulate hardware
    2. VMs run on container runtimes
    3. Containers do not require OS configuration
    4. VMs are lighter than containers

    Explanation: Containers leverage the host OS and avoid full OS configs, making them lighter. VMs are heavier, emulate hardware, and require full OS setups. VMs do not run on container runtimes but use hypervisors.

  4. Docker Image and Container

    What is the primary difference between a Docker image and a Docker container?

    1. An image always runs in the background
    2. An image is a blueprint; a container is the running app
    3. A container is always a static file
    4. A container contains no application code

    Explanation: A Docker image is a static collection of code and configuration, like a recipe, while the container is the actual running instance. The other options are incorrect or misleading about the nature of images and containers.

  5. Manual vs. Shortcut Commands

    Which single Docker command both creates and starts a container, then shows its output?

    1. docker container create hello-world
    2. docker ps
    3. docker logs
    4. docker run hello-world

    Explanation: The docker run command combines creation, starting, and output display in one step. docker ps shows running containers, docker logs only displays logs, and docker container create only prepares (but does not run) the container.

  6. Detached Mode Function

    What is the purpose of using the '-d' flag with 'docker run'?

    1. Deletes the container after execution
    2. Forces the container to use more memory
    3. Shows container logs directly
    4. Runs the container in the background

    Explanation: The '-d' flag (detached mode) allows the container to run without blocking the terminal. It does not delete anything, show logs directly, or allocate extra memory by default.

  7. Exposing Application Ports

    What does the command 'docker run -p 8080:5000' do?

    1. Runs the app on two different ports inside the container
    2. Maps port 8080 on the host to port 5000 in the container
    3. Binds port 5000 on the host to port 8080 in the container
    4. Disables networking in the container

    Explanation: This command allows outside access through host port 8080, forwarding to the container's port 5000. The second option reverses the mapping, which is incorrect. The other options are unrelated to port mapping.

  8. Cleaning Up Docker Resources

    Which command should be used to remove a Docker container after stopping it?

    1. docker logs
    2. docker rm
    3. docker ps
    4. docker rmi

    Explanation: docker rm removes a stopped container, freeing up space. docker ps lists containers, docker rmi removes images, and docker logs displays output from containers but does not delete anything.