use-workdir-not-cd
What it does
Section titled “What it does”Reports a RUN that calls cd, anywhere in its script (also in a subshell such as (cd sub && make)).
Why it matters
Section titled “Why it matters”cd changes the directory for that one RUN; the next instruction starts again in the WORKDIR, so it is easy to believe you are in a directory you are not in.
WORKDIR states the directory once, creates it when it is missing, and applies to every later RUN, CMD, ENTRYPOINT, COPY and ADD.
Example
Section titled “Example”FROM alpine:3...RUN cd /app && make...Configuration
Section titled “Configuration”dockerfile: lint: rules: use-workdir-not-cd: warn # off (default), warn, errorEnabled by the presets: dockerfile/hadolint.
Suppress one line with sudsy-disable-next-line use-workdir-not-cd in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| hadolint | DL3003 |
full |