Best Practice
Best practices and optimization rules
Run All Best Practice Rules
pathfinder scan --ruleset docker/best-practice --project .Rules
Base Image Uses :latest Tag
MEDIUMBase image uses ':latest' tag or no tag (defaults to latest). This makes builds non-reproducible.
Deprecated MAINTAINER Instruction
INFOMAINTAINER instruction is deprecated. Use LABEL org.opencontainers.image.authors instead.
apt-get Without --no-install-recommends
LOWapt-get install without --no-install-recommends. This installs unnecessary packages, increasing image size and attack surface.
Avoid apt-get upgrade
MEDIUMAvoid apt-get upgrade in Dockerfiles. Use specific base image versions instead.
Avoid dnf update
MEDIUMAvoid 'dnf update' in Dockerfiles. Use specific base image versions for reproducible builds.
Missing pipefail in Shell Commands
MEDIUMRUN instruction uses pipes without 'set -o pipefail'. This masks failures in piped commands.
Prefer COPY Over ADD
LOWUse COPY instead of ADD for simple file operations. ADD has implicit behavior that can be surprising.
Missing yum clean all
LOWRUN instruction uses 'yum install' without 'yum clean all'. This leaves package cache and increases image size.
Missing dnf clean all
LOWRUN uses 'dnf install' without 'dnf clean all'. This increases image size.
Remove apt Package Lists
LOWapt-get install without removing /var/lib/apt/lists/*. This wastes image space.
Prefer JSON Notation for CMD/ENTRYPOINT
LOWUse JSON notation (exec form) for CMD/ENTRYPOINT for proper signal handling.
Use WORKDIR Instead of cd
LOWUse WORKDIR instruction instead of 'cd' in RUN commands.
Use Absolute Path in WORKDIR
LOWWORKDIR should use absolute paths starting with /.
Avoid zypper update
MEDIUMAvoid 'zypper update' in Dockerfiles. Use specific base image versions for reproducible builds.
Missing zypper clean
LOWRUN uses 'zypper install' without 'zypper clean'. This increases image size.
Missing -y flag for apt-get
LOWapt-get install without -y flag. Add -y or --yes for non-interactive builds.
Missing HEALTHCHECK Instruction
LOWNo HEALTHCHECK instruction. Container health cannot be monitored by orchestrators, reducing reliability and observability.
Prefer apt-get over apt
LOWUse apt-get instead of apt for better script stability in Dockerfiles.
Install Only One of wget or curl
LOWInstalling both wget and curl wastes space. Choose one tool for downloads.
Missing -y flag for yum
LOWyum install without -y flag. Add -y for non-interactive builds.
Missing -y flag for dnf
LOWdnf install without -y flag. Add -y for non-interactive builds.
Avoid --platform Flag with FROM
LOWFROM with --platform flag reduces portability. Let Docker handle platform selection.
Avoid apk upgrade
MEDIUMAvoid 'apk upgrade' in Dockerfiles. Use specific base image versions instead for reproducible builds.
Avoid yum update
MEDIUMAvoid 'yum update' in Dockerfiles. Use specific base image versions for reproducible builds.
Nonsensical Command
LOWRUN command uses 'cd' which doesn't persist. Use WORKDIR instead.
apk add Without --no-cache
LOWapk add without --no-cache. Package cache remains in image, increasing size by 2-5 MB.
pip install Without --no-cache-dir
LOWpip install without --no-cache-dir. Pip cache remains in image, adding 50-200 MB depending on dependencies.
Missing Image Version
HIGHFROM instruction uses 'latest' tag or no tag. Specify explicit versions for reproducible builds.