Skip to content

pipefail-shell

Dockerfilesuspiciousno fixdefault: warndockerfile/hadolint

Reports a RUN with a pipe (a | b) in a stage whose SHELL does not set pipefail. No earlier SHELL instruction of the stage has a word that contains pipefail (SHELL ["/bin/bash", "-o", "pipefail", "-c"]). A set -o pipefail inside the RUN itself does not count. A new FROM starts the check again.

The exit status of a pipe is the one of its last command. curl -f https://example.com/x | tar xz succeeds even when curl fails and tar gets nothing, so the build goes on with a missing or broken file and the error shows up much later. With pipefail any failing command of the pipe fails the RUN.

To fix, set the option for the stage with SHELL ["/bin/bash", "-o", "pipefail", "-c"]; the default /bin/sh of some images (Debian’s dash) does not have the option.

Reported
...
RUN a | b
RUN a || b
RUN ["a", "b"]
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN a | b
FROM debian:12
RUN a | b
...
dockerfile:
lint:
rules:
pipefail-shell: warn # off, warn (default), error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line pipefail-shell in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
hadolint DL4006 partial A SHELL instruction with a word that contains pipefail ends the check for the rest of the stage.