Q. Which instruction in Dockerfile is used to specify the base image?

  • (A) BASE
  • (B) FROM
  • (C) IMAGE
  • (D) START
πŸ’¬ Discuss
βœ… Correct Answer: (B) FROM
Explanation: The `FROM` instruction sets the base image for the Docker image.

Q. What does the `RUN` instruction do in a Dockerfile?

  • (A) Defines a default command
  • (B) Executes a command at container runtime
  • (C) Executes a command at image build time
  • (D) Deletes a file
πŸ’¬ Discuss
βœ… Correct Answer: (C) Executes a command at image build time
Explanation: `RUN` is used to execute commands while building the image.

Q. Which instruction is used to specify the default command when a container starts?

  • (A) RUN
  • (B) CMD
  • (C) ENTRYPOINT
  • (D) START
πŸ’¬ Discuss
βœ… Correct Answer: (B) CMD
Explanation: `CMD` provides defaults for the executing container.

Q. How can you add metadata to an image using Dockerfile?

  • (A) META
  • (B) LABEL
  • (C) ANNOTATE
  • (D) INFO
πŸ’¬ Discuss
βœ… Correct Answer: (B) LABEL
Explanation: `LABEL` is used to add metadata as key-value pairs to Docker images.

Q. What is the difference between `CMD` and `ENTRYPOINT`?

  • (A) CMD is required; ENTRYPOINT is optional
  • (B) ENTRYPOINT allows arguments; CMD does not
  • (C) CMD provides defaults; ENTRYPOINT defines fixed commands
  • (D) They are interchangeable
πŸ’¬ Discuss
βœ… Correct Answer: (C) CMD provides defaults; ENTRYPOINT defines fixed commands
Explanation: `CMD` can be overridden, while `ENTRYPOINT` defines the main command that always runs.

Q. What is the purpose of the `COPY` instruction?

  • (A) To copy from image to host
  • (B) To copy from container to host
  • (C) To copy files from host to image
  • (D) To copy files from one image to another
πŸ’¬ Discuss
βœ… Correct Answer: (C) To copy files from host to image
Explanation: `COPY` transfers files from the local file system into the image.

Q. What does `EXPOSE 80` do in a Dockerfile?

  • (A) Starts a service on port 80
  • (B) Makes port 80 available for linking containers
  • (C) Opens a host port
  • (D) Assigns 80 as container ID
πŸ’¬ Discuss
βœ… Correct Answer: (B) Makes port 80 available for linking containers
Explanation: `EXPOSE` is a documentation instruction to inform Docker about ports the container listens on.

Q. What does `ENV APP_ENV=production` do?

  • (A) Creates a label
  • (B) Runs a command
  • (C) Sets an environment variable
  • (D) Creates a user
πŸ’¬ Discuss
βœ… Correct Answer: (C) Sets an environment variable
Explanation: `ENV` sets environment variables inside the container.

Q. Which instruction allows combining multiple commands into one layer?

  • (A) MULTI
  • (B) SHELL
  • (C) RUN with &&
  • (D) STACK
πŸ’¬ Discuss
βœ… Correct Answer: (C) RUN with &&
Explanation: Using `&&` in `RUN` chains multiple commands into one image layer.

Q. What is the result of using multiple `FROM` instructions?

  • (A) Error in build
  • (B) Multiple base images
  • (C) Multi-stage build
  • (D) Multiple containers
πŸ’¬ Discuss
βœ… Correct Answer: (C) Multi-stage build
Explanation: Multiple `FROM` instructions enable multi-stage builds for smaller, optimized images.