What is the WORKDIR instruction good for in Docker?
Experience Level: Senior
Tags: Docker
Answer
The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. If the WORKDIR doesn’t exist, it will be created even if it’s not used in any subsequent Dockerfile instruction.
The WORKDIR instruction can be used multiple times in a Dockerfile. If a relative path is provided, it will be relative to the path of the previous WORKDIR instruction.
Example:
WORKDIR /src
Related Docker job interview questions
What is the VOLUME instruction good for in Docker?
Docker SeniorCan the WORKDIR instruction resolve environment variables in Docker?
Docker SeniorWhat is the USER instruction good for in Docker?
Docker SeniorHow do you copy files to your Docker image during built while configuring permissions as well?
Docker SeniorWhat is the COPY instruction in Docker good for?
Docker Senior