WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile.
ENTRYPOINT command will be executed in the specified working directory.
WORKDIR command is not written in the Dockerfile, it will automatically be created by the Docker compiler. Hence, it can be said that the command performs
Here’s a sample Dockerfile in which the working directory is set to
FROM ubuntu:16.04 WORKDIR /project RUN npm install
project directory does not exist, it will be created. The
RUN command will be executed inside
WORKDIR can be reused to set a new working directory at any stage of the Dockerfile. The path of the new working directory must be given relative to the current working directory.
FROM ubuntu:16.04 WORKDIR /project RUN npm install WORKDIR ../project2 RUN touch file1.cpp
While directories can be manually made and changed, it is strongly recommended that you use
WORKDIR to specify the current directory in which you would like to work as it makes troubleshooting easier.