Docker
/Beginner
WORKDIR
Definition
The instruction that sets the working directory (the active folder) for any subsequent `RUN`, `CMD`, `ENTRYPOINT`, `COPY`, and `ADD` instructions that follow it in the Dockerfile.
Explain Like I'm New
Typing `cd` (change directory) in the terminal. It tells Docker 'For the rest of the recipe, do all your work inside this specific folder'.
Real World Example
`WORKDIR /app`. Now, if the next line is `COPY . .`, it copies your files directly into the `/app` folder. If you open a terminal in the live container later, you will start inside the `/app` folder.
Common Use Cases
- •Organizing container file structure
- •Best practices
Interview Questions
basic
- What happens if you set a `WORKDIR` to a folder that doesn't exist yet?
intermediate
- Why is using `WORKDIR /app` better than just writing `RUN cd /app`?