Best Practices

Docker best practices and optimization rules

28
Security Rules

Run All Best Practices Rules

pathfinder scan --ruleset cpf/docker/best-practices

Rules

Base Image Uses :latest Tag

medium

Detects FROM instructions using :latest tag which makes builds non-reproducible

dockerreproducibilitysupply-chain
Updated 2024-12-10

Missing Healthcheck

medium

Container without HEALTHCHECK instruction cannot be monitored for health status

dockermonitoringreliability
Updated 2024-12-10

Deprecated MAINTAINER Instruction

low

MAINTAINER instruction deprecated since Docker 1.13, use LABEL with OCI metadata keys instead

dockerdeprecatedbest-practice
Updated 2024-12-10

apt-get Without --no-install-recommends

low

apt-get install without --no-install-recommends bloats images by 30-50% with unnecessary packages

dockeroptimizationdebianubuntu
Updated 2024-12-10

Avoid apt-get upgrade

medium

apt-get upgrade creates non-reproducible builds. Use specific base image versions instead

dockerreproducibilitydebian
Updated 2024-12-10

apk add Without --no-cache

low

Alpine apk without --no-cache leaves package cache in image, adding 2-5 MB unnecessary data

dockeralpineoptimization
Updated 2024-12-10

pip install Without --no-cache-dir

low

pip without --no-cache-dir leaves cache in ~/.cache/pip/, adding 50-200 MB to images

dockerpythonoptimization
Updated 2024-12-10

Missing pipefail in Shell Commands

medium

Shell pipes without pipefail mask failures in earlier commands, only returning last command exit code

dockercorrectnessshell
Updated 2024-12-10

Prefer COPY Over ADD

low

ADD has implicit behavior (tar extraction, URL download) that can be surprising. Use COPY unless you need ADD features

dockerbest-practiceclarity
Updated 2024-12-10

Missing yum clean all

low

yum install without yum clean all leaves package cache, unnecessarily increasing image size

dockerrhelfedoraoptimization
Updated 2024-12-10

Missing dnf clean all

low

dnf install without dnf clean all leaves package cache, unnecessarily increasing image size

dockerrhelfedoraoptimization
Updated 2024-12-10

Remove apt Package Lists

low

apt-get without removing /var/lib/apt/lists/* wastes space with package metadata not needed at runtime

dockerdebianubuntuoptimization
Updated 2024-12-10

Missing Image Version

high

Using latest or untagged images creates non-reproducible builds that can break unexpectedly

dockerreproducibilitysupply-chain
Updated 2024-12-10

Prefer JSON Notation for CMD/ENTRYPOINT

low

Shell form wraps commands in /bin/sh -c which does not pass signals correctly. Use exec form (JSON) for proper signal handling

dockersignalsbest-practice
Updated 2024-12-10

Use WORKDIR Instead of cd

low

Using cd in RUN commands is error-prone and does not persist. WORKDIR is explicit and affects all subsequent instructions

dockerbest-practice
Updated 2024-12-10

Use Absolute Path in WORKDIR

low

WORKDIR should use absolute paths starting with /. Relative paths can be confusing and error-prone

dockerbest-practice
Updated 2024-12-10

Avoid zypper update

medium

zypper update in Dockerfiles creates non-reproducible builds. Use specific base image versions instead

dockerreproducibilitysuse
Updated 2024-12-10

Missing zypper clean

low

zypper install without zypper clean increases image size with unnecessary cache

dockersuseoptimization
Updated 2024-12-10

Missing -y flag for apt-get

low

apt-get install without -y flag may hang in non-interactive builds waiting for user input

dockerdebianubuntu
Updated 2024-12-10

Prefer apt-get over apt

low

Use apt-get instead of apt for better script stability in Dockerfiles. apt output format may change

dockerdebianubuntu
Updated 2024-12-10

Install Only One of wget or curl

low

Installing both wget and curl wastes space. Choose one tool for HTTP operations

dockeroptimization
Updated 2024-12-10

Missing -y flag for yum

low

yum install without -y flag may hang in non-interactive builds

dockerrhelfedora
Updated 2024-12-10

Missing -y flag for dnf

low

dnf install without -y flag may hang in non-interactive builds

dockerrhelfedora
Updated 2024-12-10

Avoid --platform Flag with FROM

low

FROM with --platform flag reduces portability. Let Docker handle platform selection automatically

dockerportability
Updated 2024-12-10

Avoid apk upgrade

medium

apk upgrade in Dockerfiles creates non-reproducible builds. Use specific base image versions

dockeralpinereproducibility
Updated 2024-12-10

Avoid yum update

medium

yum update creates non-reproducible builds. Use specific base image versions instead

dockerrhelfedorareproducibility
Updated 2024-12-10

Avoid dnf update

medium

dnf update creates non-reproducible builds. Use specific base image versions instead

dockerrhelfedorareproducibility
Updated 2024-12-10

Nonsensical Command

low

RUN command uses cd which does not persist across layers. Use WORKDIR instead

dockerbest-practice
Updated 2024-12-10
Best Practices Security Rules for Docker - 28 SAST Rules | Code Pathfinder | Code Pathfinder