Best Practices

Docker best practices and optimization rules

28
Security Rules

Run All Best Practices Rules

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

Rules

apk add Without --no-cache

low

Detects RUN instructions using Alpine Linux's apk add command without the --no-cache flag, which unnecessarily increases Docker image size by 2-5 MB.

dockeralpineimage-sizebest-practiceoptimization
Updated 2024-12-19

Deprecated MAINTAINER Instruction

info

Detects usage of the deprecated MAINTAINER instruction, which has been deprecated since Docker 1.13 in favor of LABEL instructions with standardized OCI metadata keys.

dockerdeprecatedbest-practicemetadataoci
Updated 2024-12-19

Missing HEALTHCHECK Instruction

low

Detects Dockerfiles without a HEALTHCHECK instruction, which prevents orchestrators from monitoring container health and automatically restarting failing containers.

dockerreliabilitymonitoringhealth-checkbest-practice
Updated 2024-12-19

pip install Without --no-cache-dir

low

Detects pip install without --no-cache-dir flag, which leaves pip cache in the image adding 50-200 MB depending on dependencies.

dockerpythonpipimage-sizebest-practiceoptimization
Updated 2024-12-19

Base Image Uses :latest Tag

medium

Detects FROM instructions using :latest tag or no tag, which makes builds non-reproducible and can introduce unexpected breaking changes or security vulnerabilities.

dockerreproducibilitybest-practiceversioningsupply-chain
Updated 2024-12-19

Avoid apk upgrade

medium

Detects use of apk upgrade in Dockerfiles, which creates unpredictable, non-reproducible builds.

dockeralpinereproducibilitybest-practice
Updated 2024-12-19

Avoid apt-get upgrade

medium

Detects use of apt-get upgrade or dist-upgrade in Dockerfiles, which creates unpredictable, non-reproducible images.

dockerdebianubuntureproducibilitybest-practice
Updated 2024-12-19

Avoid dnf update

medium

Detects use of dnf update in Dockerfiles, which creates unpredictable, non-reproducible builds.

dockerfedorarhelreproducibilitybest-practice
Updated 2024-12-19

Avoid --platform Flag with FROM

low

Detects FROM instructions with --platform flag, which reduces portability by hardcoding platform architecture.

dockerportabilitymulti-archbest-practice
Updated 2024-12-19

Avoid yum update

medium

Detects use of yum update in Dockerfiles, which creates unpredictable, non-reproducible builds.

dockercentosrhelreproducibilitybest-practice
Updated 2024-12-19

Avoid zypper update

medium

Detects use of zypper update in Dockerfiles, which creates unpredictable, non-reproducible builds.

dockersuseopensusereproducibilitybest-practice
Updated 2024-12-19

Missing -y flag for apt-get

low

Detects apt-get install without -y flag, which can cause builds to hang waiting for user input.

dockeraptdebianubuntubest-practicebuild
Updated 2024-12-19

Missing -y flag for dnf

low

Detects dnf install without -y flag for non-interactive builds.

dockerdnffedorarhelbest-practicebuild
Updated 2024-12-19

Missing dnf clean all

low

Detects dnf install commands without subsequent dnf clean all, which unnecessarily increases image size.

dockerdnffedoraimage-sizebest-practiceoptimization
Updated 2024-12-19

Missing Image Version

high

Detects FROM instructions using latest tag or no tag, creating non-reproducible builds.

dockerversioningreproducibilitybest-practice
Updated 2024-12-19

Missing -y flag for yum

low

Detects yum install without -y flag for non-interactive builds.

dockeryumcentosrhelbest-practicebuild
Updated 2024-12-19

Missing yum clean all

low

Detects yum install without yum clean all, leaving package cache and increasing image size.

dockeryumcentosimage-sizebest-practiceoptimization
Updated 2024-12-19

Missing zypper clean

low

Detects zypper install without zypper clean, which increases image size.

dockerzyppersuseimage-sizebest-practiceoptimization
Updated 2024-12-19

Nonsensical Command

low

Detects RUN commands using cd which doesn't persist between instructions. Use WORKDIR instead.

dockerbest-practiceworkdircd
Updated 2024-12-19

Prefer apt-get over apt

low

Detects use of apt instead of apt-get, which provides better script stability in Dockerfiles.

dockeraptdebianubuntubest-practice
Updated 2024-12-19

Prefer COPY Over ADD

low

Detects use of ADD instruction when COPY would suffice. ADD has implicit behavior that can be surprising and create security risks.

dockerbest-practicecopyaddtransparency
Updated 2024-12-19

Prefer JSON Notation for CMD/ENTRYPOINT

low

Detects shell form for CMD/ENTRYPOINT which doesn't handle signals correctly. Use exec form (JSON) for proper signal handling.

dockerbest-practicesignalscmdentrypoint
Updated 2024-12-19

Remove apt Package Lists

low

Detects apt-get install without removing /var/lib/apt/lists/*, which wastes image space.

dockeraptdebianubuntuimage-sizebest-practice
Updated 2024-12-19

Missing pipefail in Shell Commands

medium

Detects RUN instructions using pipes without set -o pipefail, which masks failures in piped commands.

dockershellerror-handlingbest-practicepipes
Updated 2024-12-19

Use Absolute Path in WORKDIR

low

Detects WORKDIR with relative paths, which can be confusing and error-prone.

dockerworkdirbest-practicepaths
Updated 2024-12-19

Install Only One of wget or curl

low

Detects installation of both wget and curl, which wastes space. Choose one tool for downloads.

dockerimage-sizeoptimizationwgetcurl
Updated 2024-12-19

Use WORKDIR Instead of cd

low

Detects use of cd in RUN commands without WORKDIR. WORKDIR is more explicit and persistent.

dockerworkdircdbest-practice
Updated 2024-12-19

apt-get Without --no-install-recommends

low

Detects apt-get install without --no-install-recommends flag, which installs unnecessary packages increasing image size and attack surface.

dockeraptdebianubuntuimage-sizesecuritybest-practice
Updated 2024-12-19