cheat-sheets

Ubuntu

Ubuntu is a glibc and apt based distribution. The ubuntu image is a minimal root filesystem with fewer packages than a normal install.

Documentation: Ubuntu Server docs Project: Ubuntu · Docker Hub

See also Container Distros, Debian 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
apt-get install -y PACKAGE=VERSIONPin a version
dpkg -L PACKAGEList a package’s files
dpkg -S /PATH/TO/FILEWhich package owns a file
dockerfile
FROM ubuntu:24.04
RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
      ca-certificates curl tzdata \
 && rm -rf /var/lib/apt/lists/*

Use apt-get rather than apt in scripts: apt is meant for interactive use. Setting DEBIAN_FRONTEND on the RUN line keeps it out of the final image environment.

Image Tags #

TAGMEANING
ubuntu:24.04LTS release by number (preferred)
ubuntu:nobleThe same release by codename
ubuntu:latestLatest LTS; avoid in builds
ubuntu:rollingLatest release including non-LTS (unverified)

Users #

COMMANDDESCRIPTION
useradd -r -u 10001 -m APPCreate a system user with a fixed UID and a home directory
groupadd -r GROUPCreate a system group
id ubuntuThe 24.04 image already contains an ubuntu user (UID 1000), so USER ubuntu works

CA Certificates and Timezone #

COMMANDDESCRIPTION
apt-get install -y --no-install-recommends ca-certificatesNeeded for HTTPS from a minimal image
update-ca-certificatesRebuild after adding .crt files to /usr/local/share/ca-certificates/
apt-get install -y --no-install-recommends tzdataInstall zone data
ln -fs /usr/share/zoneinfo/Europe/London /etc/localtime && dpkg-reconfigure -f noninteractive tzdataSet the timezone without a prompt
-e TZ=Europe/LondonAlternative at docker run (needs tzdata; unverified)

Gotchas #

SYMPTOMFIX
Build hangs on a tzdata or keyboard promptSet DEBIAN_FRONTEND=noninteractive for that RUN
E: Unable to locate packageRun apt-get update in the same RUN (the image ships without indexes)
curl: (60) SSL certificate problemInstall ca-certificates
Image grows after installsRemove /var/lib/apt/lists/* in the same layer
No sudo, ps, ping and similarMinimal image; install the package that provides it
Sources are in /etc/apt/sources.list.d/ubuntu.sources24.04 uses the deb822 format, not sources.list
Search all sheets

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