Dockerfile Base Image
Which Dockerfile instruction specifies the base image to use for building the container?
- IMAGE
- FROM
- BASE
- SOURCE
- USING
COPY vs. ADD
What is the primary difference between the COPY and ADD instructions in a Dockerfile?
- COPY only copies local files/directories, while ADD can also download files from URLs or extract archives.
- ADD only copies local files/directories, while COPY can also download files from URLs or extract archives.
- COPY is deprecated and ADD should be used instead.
- ADD is deprecated and COPY should be used instead.
- There is no functional difference between COPY and ADD.
CMD Instruction
Which Dockerfile instruction specifies the command to run when the container starts?
- RUN
- START
- EXEC
- CMD
- LAUNCH
WORKDIR Instruction
What is the purpose of the WORKDIR instruction in a Dockerfile?
- Specifies the directory where the Dockerfile is located.
- Sets the working directory for subsequent instructions, like RUN, CMD, COPY, and ADD.
- Defines a volume mount point within the container.
- Configures environment variables for the container.
- Specifies a temporary directory for build artifacts.
RUN Instruction
What is the primary purpose of the RUN instruction in a Dockerfile?
- To execute a command inside the container during the build process.
- To execute a command when the container is started.
- To define environment variables.
- To copy files from the host machine to the container.
- To expose a port on the container.
Dockerfile Layering
How does Docker utilize layers when building an image from a Dockerfile?
- Each instruction creates a new layer, caching intermediate results.
- All instructions are combined into a single layer.
- Only RUN instructions create layers.
- Only COPY and ADD instructions create layers.
- Layers are only created for instructions that modify the file system.
ENTRYPOINT vs. CMD
What is the difference between ENTRYPOINT and CMD in a Dockerfile?
- ENTRYPOINT specifies the executable, and CMD provides default arguments. CMD arguments can be overridden when running the container.
- CMD specifies the executable, and ENTRYPOINT provides default arguments. ENTRYPOINT arguments can be overridden when running the container.
- ENTRYPOINT and CMD are interchangeable; they perform the same function.
- ENTRYPOINT is used for applications, and CMD is used for scripts.
- CMD is used for applications, and ENTRYPOINT is used for scripts.
Environment Variables
Which instruction is used to define environment variables within a Dockerfile?
- ENV
- VARIABLE
- EXPORT
- SET
- ENVIRONMENT
EXPOSE Instruction
What is the purpose of the EXPOSE instruction in a Dockerfile?
- To publish a port to the host machine.
- To document which port the application will use, without actually publishing it.
- To specify a range of ports to be used by the application.
- To automatically forward traffic to the container.
- To configure firewall rules for the container.
Ignoring Files (.dockerignore)
What is the purpose of a `.dockerignore` file in the context of Dockerfiles?
- To specify files and directories that should be excluded from the build context.
- To specify files and directories that should be included in the build context.
- To define environment variables for the build process.
- To specify dependencies that should be installed during the build process.
- To configure logging for the build process.