Which statement is true regarding the WORKDIR directive in Docker?

Prepare for the Docker Certified Associate test with our comprehensive quizzes that include key questions and detailed explanations. Ace your certification!

The WORKDIR directive is used in a Dockerfile to set the working directory for any RUN, CMD, ENTRYPOINT, COPY, and ADD commands that follow it in the Dockerfile. The importance of the WORKDIR directive lies in its impact on the context of building an image and running a container.

The statement that WORKDIR affects only the build and not the running container is not correct, as the context in which the WORKDIR is applied extends to the final container environment. When the container is run, the working directory is set to what is defined in the WORKDIR directive, which means that all commands run within the container will operate in the specified directory.

The purpose of the WORKDIR directive is to create a consistent working environment throughout the image build process and at runtime, ensuring that the specified directory exists and is used for subsequent commands. If the WORKDIR was not set, the default working directory would typically be the root directory, which may not be desirable for many applications.

Other provided statements do not accurately describe the usage or necessity of the WORKDIR directive in Docker. For instance, while it is important for defining the working directory, it is not mandatory to use WORKDIR for building images; you can still create images without it by explicitly

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy