Skip to content

Rules

Every rule docker-doctor ships, grouped by category.

On this page

docker-doctor ships 31 rules across 5 categories. Every diagnostic carries a full rule key (e.g. docker-doctor/no-root-user) that you can pass to rules explain or use to tune severity in your config. Each rule below links to a page with failing and fixed examples.

List everything docker-doctor knows about:

npx @docker-doctor/cli@latest rules list

Explain any single rule in depth:

npx @docker-doctor/cli@latest rules explain <rule>

Security

Catches Dockerfile patterns that widen your attack surface.

RuleWhat it checksSeverity
no-root-userRun the container as a non-root userwarning
no-secrets-in-envAvoid storing secrets in ENV or ARG instructionserror
pin-image-versionPin base images to a specific tag or digestwarning
no-add-remoteAvoid using ADD with remote URLswarning

Performance

Reduces build time and layer bloat.

RuleWhat it checksSeverity
use-multi-stageUse multi-stage buildsinfo
order-layersOrder layers to maximize build cache utilitywarning
minimize-layersMinimize the number of image layersinfo
use-dockerignoreAdd a .dockerignore filewarning

Best Practices

Keeps Dockerfiles and Compose files clean and predictable.

RuleWhat it checksSeverity
require-healthcheckAdd a HEALTHCHECK instructioninfo
prefer-copy-over-addPrefer COPY over ADDwarning
use-exec-formUse exec form for CMD and ENTRYPOINTwarning
require-labelsAdd LABEL metadata to imagesinfo
combine-apt-update-installCombine apt-get update and apt-get installwarning
use-pipefailUse pipefail to catch pipeline command failureswarning
absolute-workdirUse absolute paths for WORKDIRwarning
avoid-run-cdAvoid changing directories with cd in RUNinfo
sort-multiline-argsSort multi-line arguments alphanumericallyinfo
useradd-no-log-initUse --no-log-init with useraddwarning

Compose

Catches Docker Compose-specific misconfigurations.

RuleWhat it checksSeverity
no-version-keyRemove the version key from the Compose filewarning
require-resource-limitsDefine resource limits for serviceswarning
require-restart-policySet restart policy for serviceswarning
use-depends-on-conditionUse long-form depends_on with healthcheck conditionsinfo
pin-service-imagePin service images to a specific tag or digestwarning
no-privileged-serviceDo not run services in privileged modeerror
no-docker-socket-mountDo not bind-mount the Docker socket into serviceserror
no-plaintext-secretsAvoid literal secret values in Compose environmentwarning
undefined-model-referenceService model references must be declared in top-level modelserror
pin-model-versionPin models to a specific tag or digestwarning

Image Size

Keeps final images small.

RuleWhat it checksSeverity
prefer-slim-basePrefer slim, alpine, or distroless base imagesinfo
clean-package-cacheClean up package manager cache in the same RUN layerwarning
avoid-dev-dependenciesAvoid installing dev dependencies in the final stagewarning

See Configuration to change a rule's severity or turn off a whole category.