Q. What does `VOLUME` do in Dockerfile?

  • (A) Removes files from image
  • (B) Creates persistent storage
  • (C) Increases image size
  • (D) Disables logging
πŸ’¬ Discuss
βœ… Correct Answer: (B) Creates persistent storage
Explanation: `VOLUME` defines mount points for persistent or shared data.

Q. Which instruction is best for downloading dependencies during image build?

  • (A) COPY
  • (B) ADD
  • (C) RUN curl
  • (D) RUN
πŸ’¬ Discuss
βœ… Correct Answer: (D) RUN
Explanation: `RUN` is used to execute commands like `apt-get`, `curl`, or `npm install` during image build.

Q. What’s the difference between `ADD` and `COPY`?

  • (A) `ADD` has more features than `COPY`
  • (B) `COPY` can extract archives
  • (C) `ADD` only copies files
  • (D) `COPY` supports remote URLs
πŸ’¬ Discuss
βœ… Correct Answer: (A) `ADD` has more features than `COPY`
Explanation: `ADD` supports features like extracting archives and handling URLs, while `COPY` is more straightforward.

Q. Which Dockerfile instruction defines the user to run subsequent commands?

  • (A) USER
  • (B) RUNAS
  • (C) EXEC
  • (D) LOGIN
πŸ’¬ Discuss
βœ… Correct Answer: (A) USER
Explanation: `USER` sets the UID or username for running following commands in the image.

Q. How can you reduce image size while writing Dockerfiles?

  • (A) Use larger base images
  • (B) Avoid multi-stage builds
  • (C) Use multi-stage builds
  • (D) Use many RUN instructions
πŸ’¬ Discuss
βœ… Correct Answer: (C) Use multi-stage builds
Explanation: Multi-stage builds help create lightweight, optimized final images by separating build and runtime stages.

Q. What is the default shell in Dockerfile on Linux containers?

  • (A) cmd
  • (B) /bin/bash
  • (C) /bin/sh -c
  • (D) /usr/shell
πŸ’¬ Discuss
βœ… Correct Answer: (C) /bin/sh -c
Explanation: Docker uses `/bin/sh -c` as the default shell on Linux unless overridden.

Q. Which instruction can be used to copy files with permission changes?

  • (A) COPY --chmod
  • (B) ADD --perm
  • (C) RUN cp
  • (D) USER chmod
πŸ’¬ Discuss
βœ… Correct Answer: (A) COPY --chmod
Explanation: `COPY` supports the `--chmod` flag to set file permissions during copying.

Q. Which instruction should be used to clean up cache during image build?

  • (A) CMD clean
  • (B) RUN rm -rf /var/cache && apt-get clean
  • (C) CLEAN
  • (D) RESET
πŸ’¬ Discuss
βœ… Correct Answer: (B) RUN rm -rf /var/cache && apt-get clean
Explanation: Cleaning up within a single `RUN` layer reduces final image size.

Q. How do you override a CMD at runtime?

  • (A) Using docker override
  • (B) By editing the image
  • (C) By providing a command in `docker run`
  • (D) You cannot override CMD
πŸ’¬ Discuss
βœ… Correct Answer: (C) By providing a command in `docker run`
Explanation: You can override CMD by passing a command after the image name in `docker run`.

Q. What happens if both `CMD` and `ENTRYPOINT` are defined?

  • (A) `CMD` is ignored
  • (B) `ENTRYPOINT` runs first
  • (C) `CMD` arguments are passed to `ENTRYPOINT`
  • (D) `CMD` and `ENTRYPOINT` conflict
πŸ’¬ Discuss
βœ… Correct Answer: (C) `CMD` arguments are passed to `ENTRYPOINT`
Explanation: If both are defined, `CMD` provides arguments to `ENTRYPOINT` unless CMD is overridden.