no-sudo
What it does
Section titled “What it does”Reports a RUN that calls sudo.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”FROM alpine:3RUN sudo make install...RUN wget -q https://example.com/f...RUN echo sudo cd psRUN make && \ sudo make installRUN v=$(sudo make) && echo "$(wget https://example.com/f)"ONBUILD RUN sudo makeRUN ["sudo", "make"]Configuration
Section titled “Configuration”dockerfile: lint: rules: no-sudo: warn # off (default), warn, errorEnabled by the presets: dockerfile/hadolint.
Suppress one line with sudsy-disable-next-line no-sudo 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 | DL3004 |
full |