cheat-sheets

Debian

Debian is a glibc and apt based distribution and the base under many language images such as python and node. The -slim variants drop docs and extras.

Documentation: Debian Reference Project: Debian · Docker Hub

See also Container Distros, Ubuntu and Dockerfile.

apt in Dockerfiles #

COMMANDDESCRIPTION
apt-get updateRefresh indexes; always in the same RUN as the install
apt-get install -y --no-install-recommends PACKAGEInstall without recommended extras
rm -rf /var/lib/apt/lists/*Remove the indexes at the end of the layer
apt-get purge -y --auto-remove PACKAGERemove a package and its unused dependencies
apt-cache policy PACKAGEInstalled and candidate versions
dpkg -L PACKAGEList a package’s files
dpkg -S /PATH/TO/FILEWhich package owns a file
cat /etc/debian_versionExact point release (12.15 in the image checked)
dockerfile
FROM debian:12-slim
RUN apt-get update \
 && apt-get install -y --no-install-recommends ca-certificates curl \
 && rm -rf /var/lib/apt/lists/*

Image Tags #

TAGMEANING
debian:12Major release by number (preferred)
debian:bookwormThe same release by codename
debian:12-slim / debian:bookworm-slimSmaller variant
debian:stable / debian:stable-slimFollows the current stable release, so the major version changes over time
debian:testing / debian:sidMoving development releases; not for production
debian:bookworm-YYYYMMDDDated tag for reproducibility (check the tag list on Docker Hub; unverified)

Users #

COMMANDDESCRIPTION
useradd -r -u 10001 APPCreate a system user; a UID above 999 prints a SYS_UID_MAX warning but works
useradd -u 10001 -m APPCreate a regular user with a home directory
groupadd -r GROUPCreate a system group

CA Certificates and Timezone #

COMMANDDESCRIPTION
apt-get install -y --no-install-recommends ca-certificatesNeeded for HTTPS; not in the base image
update-ca-certificatesRebuild after adding .crt files to /usr/local/share/ca-certificates/
ln -fs /usr/share/zoneinfo/Europe/London /etc/localtimeSet the timezone (/usr/share/zoneinfo is present in debian:12)
-e TZ=Europe/LondonAlternative at docker run (unverified)

Gotchas #

SYMPTOMFIX
E: Unable to locate packageRun apt-get update in the same RUN
curl: (60) SSL certificate problemInstall ca-certificates
Missing ps, pingInstall procps, iputils-ping
stable tag jumped to a new releasePin the number or codename
Sources are in /etc/apt/sources.list.d/debian.sources12 uses the deb822 format, not sources.list
Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.