WORKDIR
WORKDIR in a Dockerfile sets the current working directory for:
- All RUN commands
- All COPY and ADD commands that use relative paths
- The default directory when a container starts
In short, it’s like
cdin Linux—but it persists for the rest of the Dockerfile. It’s like saying "Hey Docker, from now on, consider this folder the 'home base' for all my operations".
Why use it?
Keeps paths clean and predictable
Without WORKDIR, we would have to use absolute paths everywhere, which can be messy:
With WORKDIR, we can simplify: