Skip to main content

What is the purpose of the WORKDIR instruction?

Junior Docker
Quick Answer WORKDIR sets the working directory for all subsequent RUN, CMD, COPY, and ENTRYPOINT instructions in the Dockerfile. If the directory doesn't exist, Docker creates it. Using WORKDIR is cleaner than cd commands inside RUN steps รขโ‚ฌโ€ it's explicit, readable, and applies consistently to all following instructions.

Answer

It sets the working directory for subsequent instructions to avoid long paths.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice