Best Practice

Best practices and optimization rules

28
Security Rules

Run All Best Practice Rules

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

Rules

apt-get Without --no-install-recommends

LOW

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

dockerdockerfileapt-getpackage-managerubuntudebianoptimizationimage-sizebest-practicebloatattack-surface
CWE-710
Updated 2026-01-17

Avoid apk upgrade

MEDIUM

Avoid 'apk upgrade' in Dockerfiles. Use specific base image versions instead for reproducible builds.

dockerdockerfileapkpackage-manageralpineupgradereproducibilitybest-practiceanti-pattern
CWE-710
Updated 2026-01-17

Avoid apt-get upgrade

MEDIUM

Avoid apt-get upgrade in Dockerfiles. Use specific base image versions instead.

dockerdockerfileapt-getupgradepackage-managerubuntudebianreproducibilitybest-practiceanti-patternbuild
CWE-710
Updated 2026-01-17

Avoid dnf update

MEDIUM

Avoid 'dnf update' in Dockerfiles. Use specific base image versions for reproducible builds.

dockerdockerfilednfpackage-managerfedorarhelupdatereproducibilitybest-practiceanti-pattern
CWE-710
Updated 2026-01-17

Avoid --platform Flag with FROM

LOW

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

dockerdockerfilefromplatformmulti-archportabilitybuildxarchitecturebest-practice
CWE-710
Updated 2026-01-17

Avoid yum update

MEDIUM

Avoid 'yum update' in Dockerfiles. Use specific base image versions for reproducible builds.

dockerdockerfileyumpackage-managercentosrhelupdatereproducibilitybest-practiceanti-pattern
CWE-710
Updated 2026-01-17

Avoid zypper update

MEDIUM

Avoid 'zypper update' in Dockerfiles. Use specific base image versions for reproducible builds.

dockerdockerfilezypperpackage-manageropensusesuseupdatereproducibilitybest-practiceanti-pattern
CWE-710
Updated 2026-01-17

Deprecated MAINTAINER Instruction

INFO

MAINTAINER instruction is deprecated. Use LABEL org.opencontainers.image.authors instead.

dockerdockerfilemaintainerlabeldeprecatedmetadatabest-practiceocistandardslegacy
CWE-710
Updated 2026-01-17

Missing -y flag for apt-get

LOW

apt-get install without -y flag. Add -y or --yes for non-interactive builds.

dockerdockerfileapt-getpackage-managerautomationci-cdbuildubuntudebianbest-practicenon-interactive
CWE-710
Updated 2026-01-17

Missing -y flag for dnf

LOW

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

dockerdockerfilednfpackage-managerfedorarhelautomationci-cdbuildbest-practicenon-interactive
CWE-710
Updated 2026-01-17

Missing dnf clean all

LOW

RUN uses 'dnf install' without 'dnf clean all'. This increases image size.

dockerdockerfilednfpackage-managerfedorarhelcachecleanupimage-sizeoptimizationbest-practice
CWE-710
Updated 2026-01-17

Missing HEALTHCHECK Instruction

LOW

No HEALTHCHECK instruction. Container health cannot be monitored by orchestrators, reducing reliability and observability.

dockerdockerfilehealthcheckmonitoringobservabilityorchestrationkubernetesreliabilitybest-practiceavailability
CWE-710
Updated 2026-01-17

Missing -y flag for yum

LOW

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

dockerdockerfileyumpackage-managercentosrhelautomationci-cdbuildbest-practicenon-interactive
CWE-710
Updated 2026-01-17

Missing yum clean all

LOW

RUN instruction uses 'yum install' without 'yum clean all'. This leaves package cache and increases image size.

dockerdockerfileyumpackage-managercentosrhelcachecleanupimage-sizeoptimizationbest-practice
CWE-710
Updated 2026-01-17

Missing zypper clean

LOW

RUN uses 'zypper install' without 'zypper clean'. This increases image size.

dockerdockerfilezypperpackage-manageropensusesusecachecleanupimage-sizeoptimizationbest-practice
CWE-710
Updated 2026-01-17

Nonsensical Command

LOW

RUN command uses 'cd' which doesn't persist. Use WORKDIR instead.

dockerdockerfilecdworkdirdirectoryshellbest-practiceanti-patternconfusing
CWE-710
Updated 2026-01-17

Prefer apt-get over apt

LOW

Use apt-get instead of apt for better script stability in Dockerfiles.

dockerdockerfileaptapt-getpackage-managerubuntudebianscriptingstabilityreproducibilitybest-practice
CWE-710
Updated 2026-01-17

Prefer COPY Over ADD

LOW

Use COPY instead of ADD for simple file operations. ADD has implicit behavior that can be surprising.

dockerdockerfilecopyaddfile-operationsbest-practicetransparencypredictabilityanti-pattern
CWE-710
Updated 2026-01-17

Prefer JSON Notation for CMD/ENTRYPOINT

LOW

Use JSON notation (exec form) for CMD/ENTRYPOINT for proper signal handling.

dockerdockerfilecmdentrypointexec-formjsonsignal-handlingbest-practiceprocess-managementpid1
CWE-710
Updated 2026-01-17

Remove apt Package Lists

LOW

apt-get install without removing /var/lib/apt/lists/*. This wastes image space.

dockerdockerfileapt-getpackage-managerubuntudebiancachecleanupimage-sizeoptimizationbest-practice
CWE-710
Updated 2026-01-17

Missing pipefail in Shell Commands

MEDIUM

RUN instruction uses pipes without 'set -o pipefail'. This masks failures in piped commands.

dockerdockerfileshellbashpipefailerror-handlingbest-practicereliabilitybuildpipes
CWE-703
Updated 2026-01-17

Use Absolute Path in WORKDIR

LOW

WORKDIR should use absolute paths starting with /.

dockerdockerfileworkdirpathabsolute-pathbest-practiceclaritymaintainabilityfilesystem
CWE-710
Updated 2026-01-17

Install Only One of wget or curl

LOW

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

dockerdockerfilewgetcurldownloadtoolsoptimizationimage-sizeredundancybest-practice
CWE-710
Updated 2026-01-17

Use WORKDIR Instead of cd

LOW

Use WORKDIR instruction instead of 'cd' in RUN commands.

dockerdockerfileworkdircddirectorybest-practicemaintainabilityclarityanti-pattern
CWE-710
Updated 2026-01-17

Base Image Uses :latest Tag

MEDIUM

Base image uses ':latest' tag or no tag (defaults to latest). This makes builds non-reproducible.

dockerdockerfilefromimagetagversionlatestreproducibilitybest-practicesupply-chainimmutability
CWE-1188
Updated 2026-01-17

apk add Without --no-cache

LOW

apk add without --no-cache. Package cache remains in image, increasing size by 2-5 MB.

dockerdockerfileapkpackage-manageralpinecacheoptimizationimage-sizebest-practicelinux
CWE-710
Updated 2026-01-17

pip install Without --no-cache-dir

LOW

pip install without --no-cache-dir. Pip cache remains in image, adding 50-200 MB depending on dependencies.

dockerdockerfilepippythonpackage-managercacheoptimizationimage-sizebest-practice
CWE-710
Updated 2026-01-17

Missing Image Version

HIGH

FROM instruction uses 'latest' tag or no tag. Specify explicit versions for reproducible builds.

dockerdockerfilefromimagetagversionlatestreproducibilitybest-practicesupply-chaindependency-management
CWE-1188
Updated 2026-01-17