sort-multiline-args
Sorting multi-line package lists in a Dockerfile alphabetically: cleaner diffs, no duplicate packages, easier reviews.
On this page
A long unsorted package list in a RUN apt-get install or apk add turns every change into a hunt: is libpq-dev already in here? Did two branches both append git at the end? This rule suggests keeping multi-line package lists sorted alphabetically.
What the rule catches
FROM debian:12-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
curl \
libpq-dev \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*Scanning this file reports:
ℹ INFO [docker-doctor/sort-multiline-args]
Multi-line package arguments are not sorted alphanumerically. Keeping them sorted makes maintenance easier and prevents duplicates.Why it matters
Sorted lists make duplicates impossible to miss, merge conflicts rarer (two branches appending to the same last line is the classic conflict), and reviews instant — a one-line diff in a sorted list is exactly the package that changed. It's the same reason import statements get sorted. Zero runtime effect, purely a maintainability win, and docker-doctor only asks for it once the list spans multiple lines.
How to fix it
Sort multi-line package installation lists (e.g. apk/apt package lists) alphabetically.
FROM debian:12-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
git \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*Rule details
- Rule key —
docker-doctor/sort-multiline-args - Category — Best Practices
- Default severity —
info - Applies to — Dockerfiles
Explain this rule from the CLI:
npx @docker-doctor/cli@latest rules explain docker-doctor/sort-multiline-argsChange its severity — or turn it off — in your config file:
// docker-doctor.config.ts
export default {
rules: {
"docker-doctor/sort-multiline-args": "off",
},
};Severity affects the health score: error findings cost more points than warning, and info costs the least.