Dockerfile Base Image
Which instruction in a Dockerfile specifies the base image to be used for the container?
- IMAGE
- FROM
- BASE
- PARENT
- SOURCE
COPY vs. ADD
What is the primary difference between the `COPY` and `ADD` instructions in a Dockerfile?
- COPY only copies files, while ADD can extract archives and fetch URLs.
- ADD only copies files, while COPY can extract archives and fetch URLs.
- COPY is deprecated and ADD should be used instead.
- ADD is deprecated and COPY should be used instead.
- They are functionally identical.
WORKDIR Instruction
Which Dockerfile instruction sets the working directory for subsequent instructions?
- PATH
- DIRECTORY
- WORKDIR
- PWD
- CHDIR
EXPOSE Instruction
What does the `EXPOSE` instruction do in a Dockerfile?
- Exposes a port for inter-container communication, but does not publish the port to the host.
- Publishes a port to the host, allowing external access.
- Defines an environment variable for the container.
- Sets the user ID for the container process.
- It is no longer used in modern Dockerfiles.
CMD Instruction
How many `CMD` instructions can a Dockerfile have, and what happens if there are multiple?
- Only one, and it's an error to have more.
- Multiple are allowed, and all are executed in order.
- Multiple are allowed, but only the last one is executed.
- Multiple are allowed, and the first one is executed.
- As many as desired, executed in parallel.
ENTRYPOINT Instruction
What is the purpose of the `ENTRYPOINT` instruction in a Dockerfile?
- To specify the command to be executed when the container starts.
- To define environment variables.
- To copy files into the container.
- To expose a port for the container.
- To specify the default user for the container.
Dockerfile Caching
Docker builds images layer by layer using the instructions in the Dockerfile. What happens if a layer doesn't change?
- Docker rebuilds all layers from scratch.
- Docker uses the cached layer, speeding up the build process.
- Docker ignores that layer and proceeds to the next one.
- The build process fails.
- Docker recompresses that layer.
RUN Instruction
What is the purpose of the `RUN` instruction in a Dockerfile?
- To execute a command within the container's filesystem during the image build process.
- To run the container in detached mode.
- To specify the name of the container.
- To map ports between the host and the container.
- To specify the resource limits for the container.
ENV Instruction Example
Which instruction correctly defines an environment variable named `MY_VAR` with the value `example` in a Dockerfile?
- VAR MY_VAR=example
- DEFINE MY_VAR=example
- SET MY_VAR=example
- ENV MY_VAR=example
- EXPORT MY_VAR=example
CMD vs ENTRYPOINT combination
If both `ENTRYPOINT` and `CMD` are used in a Dockerfile, and `ENTRYPOINT` defines an executable and `CMD` defines parameters, how are they combined?
- The `CMD` command completely replaces the `ENTRYPOINT` command.
- The `ENTRYPOINT` command completely replaces the `CMD` command.
- The `CMD` parameters are passed as arguments to the `ENTRYPOINT` executable.
- The `ENTRYPOINT` executable is ignored and only the `CMD` is executed.
- They run in parallel as separate processes.