nerdexam
LPI

305-300 · Question #96

If a Dockerfile contains the following lines: WORKDIR / RUN cd /tmp RUN echo test > test Where is the file test located?

The correct answer is C. /test within the container image. The WORKDIR instruction sets the working directory for any subsequent RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. The RUN instruction executes commands in a new layer on top of the current image and commits the results. The RUN cd command…

Containerization

Question

If a Dockerfile contains the following lines: WORKDIR / RUN cd /tmp RUN echo test > test Where is the file test located?

Options

  • A/ting/test within the container image.
  • B/root/tesc within the container image.
  • C/test within the container image.
  • D/tmp/test on the system running docker build.
  • Etest in the directory holding the Dockerf ile.

How the community answered

(18 responses)
  • B
    17% (3)
  • C
    72% (13)
  • D
    6% (1)
  • E
    6% (1)

Explanation

The WORKDIR instruction sets the working directory for any subsequent RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. The RUN instruction executes commands in a new layer on top of the current image and commits the results. The RUN cd command does not change the working directory for the next RUN instruction, because each RUN command runs in a new shell and a new environment. Therefore, the file test is created in the root directory (/) of the container image, not in the /tmp directory.

Topics

#Dockerfile#WORKDIR#RUN instruction#filesystem behavior

Community Discussion

No community discussion yet for this question.

Full 305-300 Practice