Pipeline without pipefail

Configure the shell to detect failures earlier in a pipeline.

Description

By default, a shell pipeline returns the last command’s exit status. A Docker RUN can succeed even if an earlier command failed.

Potential impact

The image can contain a partial download or incomplete output from an earlier build step.

Remediation

Choose a shell installed in the image that supports pipefail, and enable it before the RUN step. Alternatively, run the commands separately and check each exit status.

Examples

The example sets Bash’s pipefail so a failed curl makes the build step fail. To verify a downloaded script before running it, save it first and check its source and integrity.

Before

dockerfile
FROM node:22

RUN curl -fsSL https://example.com/install.sh | bash

After

dockerfile
FROM node:22

SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -fsSL https://example.com/install.sh | bash

References