Docker Fundamentals: Containers and Images Quiz Quiz

Assess your understanding of Docker containers, images, and essential commands with this beginner-friendly quiz. Enhance your knowledge of containerization concepts, image management, and basic operational tasks relevant to Docker environments.

  1. Purpose of Images

    Which statement best describes the role of an image in Docker?

    1. An image is an encrypted backup copy of your data.
    2. An image is a virtual machine with an operating system installed.
    3. An image is a read-only template used to create containers.
    4. An image is a running instance of a container.

    Explanation: Images in Docker serve as the blueprints or read-only templates for creating containers. They contain the application code, libraries, and dependencies required by the application. A running instance is called a container, not an image, so option B is incorrect. Images are not backups, so option C is misplaced. Unlike virtual machines, images do not include a complete operating system, making option D inaccurate.

  2. Starting a Container

    If you want to start a new container based on an existing image called 'webserver', which command would you use?

    1. docker image webserver
    2. docker run webserver
    3. docker build webserver
    4. docker copy webserver

    Explanation: The 'docker run' command is used to create and start a new container from a specified image. Option B, 'docker image', is used for image management rather than running containers. Option C, 'docker build', is for building new images, not running them. Option D, 'docker copy', is not a valid command for creating containers.

  3. Immutability of Images

    Why are Docker images considered 'immutable'?

    1. Because images include hidden system files.
    2. Because you can only access images with a password.
    3. Because you cannot change an image after it is created.
    4. Because images are automatically deleted after use.

    Explanation: Docker images are immutable, meaning once they are created, they cannot be changed. Any modifications require building a new image. Option B is incorrect; images are not deleted after use. Option C mentions hidden files, which is unrelated. Option D is wrong since password protection is not the reason for immutability.

  4. Viewing Active Containers

    Which command allows you to list only containers that are currently running?

    1. docker run --active
    2. docker ps
    3. docker images
    4. docker show

    Explanation: The 'docker ps' command displays all the running containers at the moment. Option B, 'docker show', is not a valid command. Option C, 'docker images', lists images not containers. Option D, 'docker run --active', is an incorrect and invalid command in this context.

  5. Layered Structure of Images

    What is the significance of layers in Docker images?

    1. Layers encrypt the files inside the container.
    2. Layers are created only for temporary files.
    3. Every layer is responsible for running a separate application.
    4. They allow for image efficiency and reuse by sharing common components.

    Explanation: Layers help Docker images save space by sharing unchanged parts between images, making them efficient and reusable. Option B incorrectly states layers encrypt files. Option C is wrong because layers aren't just for temporary files. Option D is inaccurate since layers do not separately run applications.

  6. Removing Images

    Which command removes a Docker image from your system?

    1. docker kill IMAGE_NAME
    2. docker start IMAGE_NAME
    3. docker rmi IMAGE_NAME
    4. docker clear IMAGE_NAME

    Explanation: 'docker rmi' followed by the image name deletes the specified image from your system. Option B, 'docker kill', is used for containers, not images. Option C, 'docker start', is for starting containers. Option D, 'docker clear', is not a recognized Docker command.

  7. Container Isolation

    What is the main benefit of isolation in Docker containers?

    1. It prevents containers from using the internet.
    2. It forces all containers to use the same configuration.
    3. It allows applications to run independently without affecting each other.
    4. It speeds up the boot time of your physical computer.

    Explanation: Isolation ensures that each application in a container runs separately, so one can't interfere with another. Option B is incorrect since containers can use network as needed. Option C is wrong because containers can have different configurations. Option D, about boot time, is irrelevant to container isolation.

  8. Inspecting Container Details

    How can you obtain detailed information about a running container, such as its environment variables and IP address?

    1. docker inspect CONTAINER_ID
    2. docker update CONTAINER_ID
    3. docker touch CONTAINER_ID
    4. docker history CONTAINER_ID

    Explanation: The 'docker inspect' command gives detailed information about a container's configuration and state. Option B, 'docker history', shows an image's history, not container details. Option C, 'docker update', is for modifying a container's resource limits. Option D, 'docker touch', is not a Docker command.

  9. Difference Between Containers and Images

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

    1. An image is a template, while a container is a running instance of that template.
    2. A container is always larger in size than an image.
    3. A container can generate new images automatically.
    4. An image has networking capabilities, but a container does not.

    Explanation: A Docker image acts as a blueprint, and a container is what you get when you run that blueprint. Option B is incorrect; containers do not generate new images automatically. Option C confuses terms, as both can have networking. Option D is wrong since the size depends on the specific software inside.

  10. Pulling Images

    If you want to download an image from a remote repository, which command would you use?

    1. docker push IMAGE_NAME
    2. docker fetch IMAGE_NAME
    3. docker grab IMAGE_NAME
    4. docker pull IMAGE_NAME

    Explanation: 'docker pull' fetches an image from a remote repository to your local system. Option B, 'docker push', uploads an image rather than downloads. Options C and D, 'docker fetch' and 'docker grab', are not valid Docker commands.