Q. What is the purpose of the `FROM` instruction in a Dockerfile?

  • (A) To define environment variables
  • (B) To specify the base image
  • (C) To expose ports
  • (D) To start a container
πŸ’¬ Discuss
βœ… Correct Answer: (B) To specify the base image
Explanation: `FROM` sets the base image for the Docker image being built.

Q. Which Dockerfile instruction copies files from the host system to the container?

  • (A) MOVE
  • (B) GET
  • (C) COPY
  • (D) PASTE
πŸ’¬ Discuss
βœ… Correct Answer: (C) COPY
Explanation: `COPY` copies files and directories from the host machine to the image.

Q. What is the function of the `CMD` instruction?

  • (A) Defines the image entry point
  • (B) Runs during the build process
  • (C) Provides default arguments for the container
  • (D) Builds the image
πŸ’¬ Discuss
βœ… Correct Answer: (C) Provides default arguments for the container
Explanation: `CMD` provides defaults for executing the container.

Q. Which instruction sets the working directory inside a Docker container?

  • (A) WORKINGDIR
  • (B) DIR
  • (C) WORKDIR
  • (D) SETDIR
πŸ’¬ Discuss
βœ… Correct Answer: (C) WORKDIR
Explanation: `WORKDIR` sets the working directory for instructions like `RUN`, `CMD`, etc.

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

  • (A) Opens a file
  • (B) Publishes a container to a repository
  • (C) Informs Docker that the container listens on a port
  • (D) Starts a process
πŸ’¬ Discuss
βœ… Correct Answer: (C) Informs Docker that the container listens on a port
Explanation: `EXPOSE` documents which ports are intended to be published.

Q. How can you specify environment variables in a Dockerfile?

  • (A) SETENV
  • (B) ENV
  • (C) VARIABLE
  • (D) DEFINE
πŸ’¬ Discuss
βœ… Correct Answer: (B) ENV
Explanation: The `ENV` instruction sets environment variables.

Q. Which Dockerfile instruction is used to add metadata to an image?

  • (A) LABEL
  • (B) ENV
  • (C) META
  • (D) INFO
πŸ’¬ Discuss
βœ… Correct Answer: (A) LABEL
Explanation: `LABEL` provides metadata as key-value pairs.

Q. Which instruction is used to run scripts after a container starts?

  • (A) RUN
  • (B) CMD
  • (C) SCRIPT
  • (D) AFTER
πŸ’¬ Discuss
βœ… Correct Answer: (B) CMD
Explanation: `CMD` is used to provide the default command for a container when it starts.

Q. How can you copy files with permissions preserved?

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

Q. Which instruction allows downloading and extracting tar files automatically?

  • (A) COPY
  • (B) GET
  • (C) ADD
  • (D) RUN
πŸ’¬ Discuss
βœ… Correct Answer: (C) ADD
Explanation: `ADD` can download and extract compressed tar files.