Skip to content

use-workdir-not-cd

Dockerfilestyleno fixdefault: offdockerfile/hadolint

Reports a RUN that calls cd, anywhere in its script (also in a subshell such as (cd sub && make)).

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.

Reported
FROM alpine:3
...
RUN cd /app && make
...
dockerfile:
lint:
rules:
use-workdir-not-cd: warn # off (default), warn, error

Enabled 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.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
hadolint DL3003 full