cheat-sheets

Amazon Linux

Amazon Linux 2023 (AL2023) is AWS’s RPM based distribution, derived from Fedora packages. Use the amazonlinux image to match an AWS host, for example for Lambda custom runtimes or EC2.

Documentation: AL2023 User Guide Project: Amazon Linux · Docker Hub

See also Container Distros, Fedora and Dockerfile.

dnf in Dockerfiles #

AL2023 uses dnf 4 (4.14.0 in the image checked). There is no microdnf in amazonlinux:2023; use dnf. yum is also present.

COMMANDDESCRIPTION
dnf -y install --setopt=install_weak_deps=False PACKAGEInstall without weak dependencies
dnf clean allRemove cached metadata (run in the same layer)
dnf -y upgradeUpgrade installed packages
dnf search TERMSearch packages
dnf provides /PATH/TO/FILEWhich package provides a file
dnf repolistShow enabled repositories (amazonlinux by default)
rpm -qf /PATH/TO/FILEWhich installed package owns a file
rpm -q PACKAGECheck a package and its version
dockerfile
FROM amazonlinux:2023
RUN dnf -y install --setopt=install_weak_deps=False tar gzip \
 && dnf clean all

Image Tags #

TAGMEANING
amazonlinux:2023AL2023, release stream (preferred)
amazonlinux:2Amazon Linux 2, the older generation; check AWS for its end-of-support date
amazonlinux:latestAvoid in builds

Dated tags such as 2023.12.20261102 exist (the image checked reports that in /etc/system-release).

Users #

COMMANDDESCRIPTION
dnf -y install shadow-utilsuseradd is not in the base image; install this first
useradd -r -u 10001 APPCreate a system user; a UID above 999 can print a SYS_UID_MAX warning (unverified on AL2023)

CA Certificates and Timezone #

COMMANDDESCRIPTION
update-ca-trustRebuild the trust store after adding certificates to /etc/pki/ca-trust/source/anchors/
ln -sf /usr/share/zoneinfo/Europe/London /etc/localtimeSet the timezone (/usr/share/zoneinfo is present)

The CA bundle, curl and bash are already in the image.

Gotchas #

SYMPTOMFIX
curl conflicts when installing the full packageThe image ships curl-minimal; use dnf install --allowerasing curl to swap it
useradd: command not foundInstall shadow-utils
which, tar, gzip missingMinimal image; install them
microdnf: not foundNot shipped; use dnf
Guides for Amazon Linux 2 do not applyAL2 used yum, amazon-linux-extras and a different release model; AL2023 uses dnf
Search all sheets

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