Docker MCQs – Docker Images

11.) How do you view the layers of a Docker image?

A) docker history
B) docker inspect
C) docker layers
D) docker logs

Answer: Option A

Explanation: The docker history command shows the layers of a Docker image.

12.) What is the default Docker image registry?

A) Google Container Registry
B) AWS Elastic Container Registry
C) Docker Hub
D) Azure Container Registry

Answer: Option C

Explanation: The default Docker image registry is Docker Hub.

13.) What does the docker rmi command do?

A) Removes a running container
B) Removes an unused Docker image
C) Removes all Docker containers
D) Removes Docker networking configurations

Answer: Option B

Explanation: The docker rmi command removes a Docker image from the local system.

14.) What is a lightweight base image commonly used in Docker?

A) Ubuntu
B) CentOS
C) Alpine
D) Fedora

Answer: Option C

Explanation: Alpine is a lightweight Linux distribution frequently used as a base image to minimize image size.

15.) What does the docker tag command do?

A) Builds a new Docker image
B) Deletes a Docker image
C) Pushes an image to a registry
D) Assigns a tag to a Docker image

Answer: Option D

Explanation: The docker tag command assigns a new tag to an existing Docker image.

16.) Which instruction in a Dockerfile is used to run a command during the build process?

A) RUN
B) CMD
C) ENTRYPOINT
D) WORKDIR

Answer: Option A

Explanation: The RUN instruction executes a command during the image build process and creates a new image layer.

17.) What does the FROM instruction in a Dockerfile do?

A) Starts a new container
B) Specifies the base image for the new Docker image
C) Sets the working directory in the container
D) Copies files to the container

Answer: Option B

Explanation: The FROM instruction specifies the base image for the Docker image being built.

18.) What is the purpose of the COPY instruction in a Dockerfile?

A) To copy files from one container to another
B) To move files within the container
C) To create a backup of the Docker image
D) To copy files from the local machine to the image during build

Answer: Option D

Explanation: The COPY instruction copies files or directories from the local machine to the Docker image during the build process.

19.) What is the primary purpose of the CMD instruction in a Dockerfile?

A) CMD sets the base image
B) CMD provides default commands
C) CMD defines executable instructions
D) CMD is for environment variables

Answer: Option B

Explanation: The CMD instruction in a Dockerfile is used to specify the default command that should be run when a container is started. It provides defaults that can include an executable, or they can include additional arguments that can be passed to the ENTRYPOINT.

20.) What is the primary purpose of the ENTRYPOINT instruction in a Dockerfile?

A) ENTRYPOINT sets the base image
B) ENTRYPOINT provides default commands
C) ENTRYPOINT defines executable instructions
D) ENTRYPOINT is for environment variables

Answer: Option C

Explanation: The ENTRYPOINT instruction in a Dockerfile defines the command that will always be executed when the container starts. Unlike CMD, it is more rigid and cannot be overridden by providing arguments on the docker run command line. It’s used to specify a command that you want to run, regardless of any command line arguments passed at runtime.

Leave a Reply

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