Skip to content

no-sudo

Dockerfilecorrectnessno fixdefault: offdockerfile/hadolint

Reports a RUN that calls sudo.

A RUN already runs as the user of the last USER instruction, root by default, so sudo adds nothing. Most images do not have it installed, and where it exists it may ask for a password or reset the environment (HOME, PATH), so the command sees something else than the rest of the build.

For a step that needs root, put USER root before it and switch back after it; to drop privileges at start, use a tool such as gosu in the entrypoint.

Reported
FROM alpine:3
RUN sudo make install
...
RUN wget -q https://example.com/f
...
RUN echo sudo cd ps
RUN make && \
sudo make install
RUN v=$(sudo make) && echo "$(wget https://example.com/f)"
ONBUILD RUN sudo make
RUN ["sudo", "make"]
dockerfile:
lint:
rules:
no-sudo: warn # off (default), warn, error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line no-sudo 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 DL3004 full