Docker MCQs – Docker Images

Docker images are a core concept of Docker, representing the blueprint for containers. They contain the application, its dependencies, and all necessary configurations to run consistently across environments. Mastering Docker images is crucial for understanding containerization.

These top MCQs test your knowledge about building, managing, and optimizing Docker images. Understanding these topics will help you confidently answer interview questions related to Docker images and their practical usage.

1.) What is a Docker image?

A) A virtual machine template
B) A tool for monitoring containers
C) A configuration file for Docker containers
D) A lightweight, standalone executable package containing application code and dependencies

Answer: Option D

Explanation: A Docker image is a lightweight, standalone, and executable package containing the application, its runtime, libraries, and dependencies.

2.) What is the base image in Docker?

A) An empty Docker container
B) The first layer of any Docker image
C) A custom-built image from scratch
D) The default image used for all containers

Answer: Option B

Explanation: A base image is the first layer of a Docker image, often derived from popular OS distributions like Ubuntu or Alpine.

3.) What file is used to build a Docker image?

A) Dockerfile
B) ImageConfig
C) DockerConfig.json
D) ImageBuilder

Answer: Option A

Explanation: A Dockerfile is a text file that contains instructions to build a Docker image.

4.) Which command is used to build a Docker image from a Dockerfile?

A) docker run
B) docker build
C) docker create
D) docker image

Answer: Option B

Explanation: The docker build command is used to build a Docker image from a Dockerfile.

5.) Where are Docker images stored locally by default?

A) /var/docker/images
B) /usr/lib/docker
C) /var/lib/docker
D) /etc/docker/images

Answer: Option C

Explanation: Docker images are stored locally in the /var/lib/docker directory by default.

6.) What is a multi-stage build in Docker?

A) Building multiple containers simultaneously
B) Using multiple base images in a single Dockerfile
C) Optimizing Docker images by using intermediate stages to reduce image size
D) Running multiple containers in parallel

Answer: Option C

Explanation: A multi-stage build uses intermediate stages in the Dockerfile to optimize the final image and reduce its size.

7.) How do you push a Docker image to Docker Hub?

A) docker push <image>
B) docker upload <image>
C) docker save <image>
D) docker deploy <image>

Answer: Option A

Explanation: The docker push command uploads an image to Docker Hub or any configured registry.

8.) Which command lists all the locally available Docker images?

A) docker ps
B) docker inspect
C) docker ls
D) docker images

Answer: Option D

Explanation: The docker images command lists all Docker images stored locally.

9.) How do you tag a Docker image during the build process?

A) By using the -name flag
B) By using the -t flag
C) By using the –image flag
D) By renaming the Dockerfile

Answer: Option B

Explanation: The -t flag is used with docker build to tag a Docker image (e.g., docker build -t my-image:1.0 .).

10.) What does the docker pull command do?

A) Creates a new Docker image
B) Deletes a Docker image
C) Downloads a Docker image from a registry
D) Runs a container from a Docker image

Answer: Option C

Explanation: The docker pull command downloads a Docker image from a registry like Docker Hub.

Leave a Reply

Your email address will not be published. Required fields are marked *