The WORKDIR
command is used to define the working directory of a Docker container at any given time for any RUN, CMD, ENTRYPOINT, COPY
and ADD
instructions that follow it in the Dockerfile.
WORKDIR /path/to/workdir
Note: It can be run multiple times in a Dockerfile
. If WORKDIR
doesn't exist, it will be created. And if a relative path is provided, it will be relative to previous WORKDIR
instruction.
WORKDIR
instructionsWORKDIR /c
WORKDIR d
WORKDIR e
RUN pwd // Output will be /c/d/e
ENV DIRPATH=/path/to/directory
WORKDIR $DIRPATH/$DIRNAME
RUN pwd
And the output will be /path/to/directory/$DIRNAME
Note: If the path is not specified, the default working directory /
will be used.