Q. What command builds an image using a Dockerfile?

  • (A) docker run
  • (B) docker image create
  • (C) docker build
  • (D) docker make
πŸ’¬ Discuss
βœ… Correct Answer: (C) docker build
Explanation: `docker build` is used to create images from a Dockerfile.

Q. What does each line in a Dockerfile represent?

  • (A) A new container
  • (B) A new file
  • (C) A new layer
  • (D) A new variable
πŸ’¬ Discuss
βœ… Correct Answer: (C) A new layer
Explanation: Each instruction adds a new image layer.

Q. What flag skips the cache when building a Docker image?

  • (A) --skip-cache
  • (B) --no-cache
  • (C) --build-clean
  • (D) --ignore-cache
πŸ’¬ Discuss
βœ… Correct Answer: (B) --no-cache
Explanation: `--no-cache` ensures Docker doesn’t use any cached layers.

Q. What is the default shell used by `RUN` in a Dockerfile?

  • (A) bash
  • (B) zsh
  • (C) /bin/sh -c
  • (D) /bin/bash
πŸ’¬ Discuss
βœ… Correct Answer: (C) /bin/sh -c
Explanation: The default shell for `RUN` is `/bin/sh -c` unless overridden.

Q. Which instruction is used to configure the container at runtime?

  • (A) ENV
  • (B) RUN
  • (C) CMD
  • (D) LABEL
πŸ’¬ Discuss
βœ… Correct Answer: (C) CMD
Explanation: `CMD` configures the command to run at container runtime.

Q. What should you do to reduce image size?

  • (A) Use multiple RUN statements
  • (B) Use base image with GUI
  • (C) Use multi-stage builds
  • (D) Use MAINTAINER
πŸ’¬ Discuss
βœ… Correct Answer: (C) Use multi-stage builds
Explanation: Multi-stage builds help separate build tools from the final image.

Q. Can a Dockerfile contain comments?

  • (A) No
  • (B) Yes, using //
  • (C) Yes, using #
  • (D) Yes, using ;
πŸ’¬ Discuss
βœ… Correct Answer: (C) Yes, using #
Explanation: Comments in Dockerfiles begin with `#`.

Q. Which instruction should be placed at the beginning of a Dockerfile?

  • (A) CMD
  • (B) RUN
  • (C) COPY
  • (D) FROM
πŸ’¬ Discuss
βœ… Correct Answer: (D) FROM
Explanation: `FROM` must be the first instruction in any valid Dockerfile.

Q. What is a Docker volume primarily used for?

  • (A) Networking
  • (B) Data persistence
  • (C) Container orchestration
  • (D) Image optimization
πŸ’¬ Discuss
βœ… Correct Answer: (B) Data persistence
Explanation: Docker volumes are used to persist data generated and used by Docker containers.

Q. Which command is used to create a Docker volume?

  • (A) docker create volume
  • (B) docker volume new
  • (C) docker volume create
  • (D) docker volume init
πŸ’¬ Discuss
βœ… Correct Answer: (C) docker volume create
Explanation: The `docker volume create` command is used to create a new volume.