MCQs Questions on Working with Docker Images | Docker Multiple Choice Questions

Master the essentials of Docker with this set of Docker MCQ questions and answers designed to test your expertise in creating and managing Docker images, writing Dockerfiles, and optimizing them using best practices. This guide will cover pulling, tagging, and pushing images, multi-stage builds, and techniques for optimizing image sizes.


Multiple Choice Questions (MCQs)

Creating and Managing Docker Images

  1. What is a Docker image?
    a) A running instance of a container
    b) A read-only template used to create containers
    c) A script to automate builds
    d) A storage volume for containers
  2. Which command is used to build a Docker image?
    a) docker run
    b) docker build
    c) docker create
    d) docker init
  3. What is the default name of a Dockerfile?
    a) imagefile
    b) Dockerfile
    c) Containerfile
    d) Buildfile
  4. How can you view the list of available Docker images locally?
    a) docker ls
    b) docker list images
    c) docker images
    d) docker show
  5. What does the docker rmi command do?
    a) Removes a running container
    b) Deletes a Docker image
    c) Rebuilds an image
    d) Lists all images

Pulling, Tagging, and Pushing Images

  1. Which command is used to pull a Docker image from Docker Hub?
    a) docker download
    b) docker pull
    c) docker fetch
    d) docker get
  2. What is the purpose of tagging a Docker image?
    a) To group multiple containers
    b) To assign a unique identifier to an image version
    c) To compress the image
    d) To rename the image
  3. Which command is used to push a Docker image to a remote repository?
    a) docker deploy
    b) docker upload
    c) docker push
    d) docker send
  4. What is the default Docker image repository?
    a) GitHub
    b) Docker Hub
    c) AWS ECR
    d) Google Cloud
  5. How can you rename a Docker image?
    a) docker rename
    b) docker retag
    c) docker tag
    d) docker alter

Writing Dockerfiles (Best Practices)

  1. What keyword is used in a Dockerfile to specify the base image?
    a) FROM
    b) BASE
    c) IMAGE
    d) START
  2. Which command in a Dockerfile copies files from the local machine to the image?
    a) ADD
    b) COPY
    c) MOVE
    d) IMPORT
  3. What is the purpose of the CMD instruction in a Dockerfile?
    a) To define the default command to run in the container
    b) To execute a script during build
    c) To expose container ports
    d) To define environment variables
  4. How can you reduce the size of a Docker image?
    a) Use fewer RUN instructions
    b) Combine multiple RUN commands
    c) Use smaller base images
    d) All of the above
  5. What does the .dockerignore file do?
    a) Ignores build errors
    b) Excludes files from being copied into the image
    c) Disables certain Docker commands
    d) Prevents image compression

Multi-Stage Builds

  1. What is the main purpose of multi-stage builds?
    a) To speed up the Docker build process
    b) To reduce the size of the final image
    c) To allow parallel building of images
    d) To create multiple containers at once
  2. Which Dockerfile instruction is key to multi-stage builds?
    a) CMD
    b) WORKDIR
    c) FROM
    d) RUN
  3. In a multi-stage build, what happens to intermediate stages?
    a) They are saved for debugging purposes
    b) They are discarded after the build completes
    c) They are compressed and added to the final image
    d) They are run as separate containers
  4. How do you copy artifacts from one stage to another in a multi-stage build?
    a) Using the COPY --from flag
    b) Using the ADD command
    c) By mounting a shared volume
    d) Using the INCLUDE command
  5. Why are multi-stage builds commonly used for production images?
    a) To simplify the deployment process
    b) To separate development and production dependencies
    c) To improve runtime performance
    d) All of the above

Optimizing Image Sizes

  1. What is an Alpine image in Docker?
    a) A minimal Linux-based image
    b) A base image for data processing
    c) A specialized image for debugging
    d) An image with pre-installed software
  2. Why should you avoid using latest as a tag in production images?
    a) It can lead to unpredictable updates
    b) It makes debugging harder
    c) It increases image size
    d) It consumes more memory
  3. How can you remove unused Docker images?
    a) docker clean
    b) docker prune
    c) docker rmi –all
    d) docker rm images
  4. What is the primary benefit of using a slim image?
    a) Faster builds
    b) Reduced attack surface
    c) Smaller image size
    d) All of the above
  5. Which of the following can increase Docker image size unnecessarily?
    a) Including unnecessary files
    b) Using large base images
    c) Running multiple RUN commands
    d) All of the above
  6. How can you clean up dangling images?
    a) docker cleanup
    b) docker rmi dangling
    c) docker image prune
    d) docker remove unused
  7. Which command lists the size of Docker images?
    a) docker images –size
    b) docker image ls –size
    c) docker ls images –size
    d) docker inspect size
  8. What does the --squash flag do in docker build?
    a) Combines layers into a single layer
    b) Deletes unused layers
    c) Compresses the image
    d) Optimizes build cache
  9. Why is layer caching important in Docker builds?
    a) It speeds up subsequent builds
    b) It reduces image size
    c) It allows rollback to previous layers
    d) All of the above
  10. Which of these is not a best practice for optimizing Docker images?
    a) Using multi-stage builds
    b) Avoiding large base images
    c) Adding temporary files for debugging
    d) Using .dockerignore

Answer Table

QnoAnswer
1b) A read-only template used to create containers
2b) docker build
3b) Dockerfile
4c) docker images
5b) Deletes a Docker image
6b) docker pull
7b) To assign a unique identifier to an image version
8c) docker push
9b) Docker Hub
10c) docker tag
11a) FROM
12b) COPY
13a) To define the default command to run in the container
14d) All of the above
15b) Excludes files from being copied into the image
16b) To reduce the size of the final image
17c) FROM
18b) They are discarded after the build completes
19a) Using the COPY --from flag
20d) All of the above
21a) A minimal Linux-based image
22a) It can lead to unpredictable updates
23b) docker prune
24d) All of the above
25d) All of the above
26c) docker image prune
27b) docker image ls –size
28a) Combines layers into a single layer
29a) It speeds up subsequent builds
30c) Adding temporary files for debugging

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top