Q. What happens if multiple `CMD` instructions are in a Dockerfile?

  • (A) All are executed
  • (B) Only the first is used
  • (C) Only the last is used
  • (D) They are ignored
πŸ’¬ Discuss
βœ… Correct Answer: (C) Only the last is used
Explanation: Only the final `CMD` instruction is used in the image.

Q. What is the best practice when copying large files in a Dockerfile?

  • (A) Use multiple `COPY` steps
  • (B) Combine into a single `COPY` step
  • (C) Use `RUN` instead
  • (D) Use `LABEL`
πŸ’¬ Discuss
βœ… Correct Answer: (B) Combine into a single `COPY` step
Explanation: Combining multiple copies into one reduces image layers and size.

Q. How do you specify a maintainer for a Docker image?

  • (A) LABEL maintainer="email"
  • (B) ENV MAINTAINER
  • (C) MAINTAINER
  • (D) USER
πŸ’¬ Discuss
βœ… Correct Answer: (A) LABEL maintainer="email"
Explanation: The `MAINTAINER` instruction is deprecated; use `LABEL` instead.

Q. Which instruction sets the user to execute subsequent commands?

  • (A) RUN AS
  • (B) USER
  • (C) SETUSER
  • (D) LOGIN
πŸ’¬ Discuss
βœ… Correct Answer: (B) USER
Explanation: `USER` defines which user will run the container or build steps.

Q. What is multi-stage build in Dockerfile?

  • (A) Builds images in multiple parts for debugging
  • (B) Using `RUN` multiple times
  • (C) Using multiple `FROM` statements to reduce image size
  • (D) A way to run multiple containers
πŸ’¬ Discuss
βœ… Correct Answer: (C) Using multiple `FROM` statements to reduce image size
Explanation: Multi-stage builds allow you to use one stage to build and another to package the final image.

Q. What is the effect of using `ENTRYPOINT` with `CMD`?

  • (A) `CMD` replaces `ENTRYPOINT`
  • (B) `CMD` provides arguments to `ENTRYPOINT`
  • (C) `ENTRYPOINT` overrides `CMD`
  • (D) Both are ignored
πŸ’¬ Discuss
βœ… Correct Answer: (B) `CMD` provides arguments to `ENTRYPOINT`
Explanation: When used together, `CMD` supplies default arguments to `ENTRYPOINT`.

Q. Where should the Dockerfile be placed?

  • (A) Anywhere in the system
  • (B) Inside /usr/local
  • (C) Root of the build context
  • (D) Docker directory
πŸ’¬ Discuss
βœ… Correct Answer: (C) Root of the build context
Explanation: Dockerfile must be in the build context root directory.

Q. What is the extension of a Dockerfile?

  • (A) .docker
  • (B) .df
  • (C) .dock
  • (D) No extension
πŸ’¬ Discuss
βœ… Correct Answer: (D) No extension
Explanation: Dockerfiles typically have no extension and are just named `Dockerfile`.

Q. Which instruction can download files from a remote URL?

  • (A) COPY
  • (B) GET
  • (C) ADD
  • (D) RUN download
πŸ’¬ Discuss
βœ… Correct Answer: (C) ADD
Explanation: `ADD` can fetch files from remote URLs, though `COPY` is preferred for local files.

Q. Which instruction in Dockerfile is deprecated?

  • (A) ENV
  • (B) EXPOSE
  • (C) MAINTAINER
  • (D) COPY
πŸ’¬ Discuss
βœ… Correct Answer: (C) MAINTAINER
Explanation: `MAINTAINER` is deprecated and replaced by `LABEL`.