merge-consecutive-run
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”FROM debian:12RUN aRUN b# a comment between does not matterRUN cENV A=1RUN dRUN e && f...RUN h $(i)RUN jRUN --mount=type=cache,target=/x kRUN --mount=type=cache,target=/x lRUN mRUN ["n", "o"]RUN ["p"]
...RUN a || b...Configuration
Section titled “Configuration”dockerfile: lint: rules: merge-consecutive-run: warn # off (default), warn, errorEnabled by the presets: dockerfile/hadolint.
Suppress one line with sudsy-disable-next-line merge-consecutive-run in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”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. |