Skip to content

merge-consecutive-run

Dockerfileperformanceno fixdefault: offdockerfile/hadolint

Reports a RUN that could be merged into the RUN before it. Both are one simple command, with the same leading options (--mount=...). A comment between the two does not break the pair; any other instruction does. A RUN with &&, ; or a pipe is neither reported nor part of a pair.

Every RUN creates an image layer. Files that one RUN writes and the next one deletes (a download, a package cache) still sit in the earlier layer and count toward the image size; joined with && in one RUN, the cleanup really removes them.

The price is a coarser build cache: when any part of the joined RUN changes, all of it runs again.

Reported
FROM debian:12
RUN a
RUN b
# a comment between does not matter
RUN c
ENV A=1
RUN d
RUN e && f
...
RUN h $(i)
RUN j
RUN --mount=type=cache,target=/x k
RUN --mount=type=cache,target=/x l
RUN m
RUN ["n", "o"]
RUN ["p"]
...
RUN a || b
...
dockerfile:
lint:
rules:
merge-consecutive-run: warn # off (default), warn, error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line merge-consecutive-run 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 DL3059 partial Both RUNs must be a single command with the same flags.