Docker Basics: Containerization Quiz Quiz

  1. Dockerfile Base Image

    Which instruction in a Dockerfile specifies the base image to be used for the container?

    1. IMAGE
    2. FROM
    3. BASE
    4. PARENT
    5. SOURCE
  2. COPY vs. ADD

    What is the primary difference between the `COPY` and `ADD` instructions in a Dockerfile?

    1. COPY only copies files, while ADD can extract archives and fetch URLs.
    2. ADD only copies files, while COPY can extract archives and fetch URLs.
    3. COPY is deprecated and ADD should be used instead.
    4. ADD is deprecated and COPY should be used instead.
    5. They are functionally identical.
  3. WORKDIR Instruction

    Which Dockerfile instruction sets the working directory for subsequent instructions?

    1. PATH
    2. DIRECTORY
    3. WORKDIR
    4. PWD
    5. CHDIR
  4. EXPOSE Instruction

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

    1. Exposes a port for inter-container communication, but does not publish the port to the host.
    2. Publishes a port to the host, allowing external access.
    3. Defines an environment variable for the container.
    4. Sets the user ID for the container process.
    5. It is no longer used in modern Dockerfiles.
  5. CMD Instruction

    How many `CMD` instructions can a Dockerfile have, and what happens if there are multiple?

    1. Only one, and it's an error to have more.
    2. Multiple are allowed, and all are executed in order.
    3. Multiple are allowed, but only the last one is executed.
    4. Multiple are allowed, and the first one is executed.
    5. As many as desired, executed in parallel.
  6. ENTRYPOINT Instruction

    What is the purpose of the `ENTRYPOINT` instruction in a Dockerfile?

    1. To specify the command to be executed when the container starts.
    2. To define environment variables.
    3. To copy files into the container.
    4. To expose a port for the container.
    5. To specify the default user for the container.
  7. Dockerfile Caching

    Docker builds images layer by layer using the instructions in the Dockerfile. What happens if a layer doesn't change?

    1. Docker rebuilds all layers from scratch.
    2. Docker uses the cached layer, speeding up the build process.
    3. Docker ignores that layer and proceeds to the next one.
    4. The build process fails.
    5. Docker recompresses that layer.
  8. RUN Instruction

    What is the purpose of the `RUN` instruction in a Dockerfile?

    1. To execute a command within the container's filesystem during the image build process.
    2. To run the container in detached mode.
    3. To specify the name of the container.
    4. To map ports between the host and the container.
    5. To specify the resource limits for the container.
  9. ENV Instruction Example

    Which instruction correctly defines an environment variable named `MY_VAR` with the value `example` in a Dockerfile?

    1. VAR MY_VAR=example
    2. DEFINE MY_VAR=example
    3. SET MY_VAR=example
    4. ENV MY_VAR=example
    5. EXPORT MY_VAR=example
  10. 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?

    1. The `CMD` command completely replaces the `ENTRYPOINT` command.
    2. The `ENTRYPOINT` command completely replaces the `CMD` command.
    3. The `CMD` parameters are passed as arguments to the `ENTRYPOINT` executable.
    4. The `ENTRYPOINT` executable is ignored and only the `CMD` is executed.
    5. They run in parallel as separate processes.