DL3003: Use WORKDIR to switch directories
Warning Efficiency
Why This Matters
Using `cd` inside RUN instructions does not persist across layers because each RUN starts in the WORKDIR. Chaining `cd dir && command` works but makes the Dockerfile harder to read and maintain. Developers often forget that `cd` in one RUN does not affect the next, which leads to path-related bugs. WORKDIR is the idiomatic way to set the working directory and it persists across all subsequent instructions.
How to Fix
Replace cd with a WORKDIR instruction
Before (incorrect)
RUN cd /app && npm install After (correct)
WORKDIR /app
RUN npm install Rule Details
- Rule Code
- DL3003
- Severity
- Warning
- Category
- Efficiency
Related Rules
DL3014 Warning
Use the -y switch for apt-get install
DL4006 Warning
Set the SHELL option -o pipefail before RUN with a pipe in
DL3042 Warning
Avoid use of cache directory with pip
DL3059 Info
Multiple consecutive RUN instructions
DL3015 Info
Avoid additional packages by specifying --no-install-recommends