Chapter 21: Containers with Podman

Podman containers cheat sheet

The chapter on one page: what to remember, the commands to have at your fingertips, and flashcards for quick revision.

The chapter in eight sentences

Cheat sheet

Run

CommandDoes
podman pull FULLNAME · podman imagesGet and list images
podman run --rm IMAGE cmdOne-off container
podman run -d --name N -p 8080:8080 IMAGEBackground container
podman ps [-a] · podman logs N · podman exec N cmdLook inside
podman stop -t 1 N · podman rm [-f] N · podman rmi IMAGEStop and remove

Data and build

CommandDoes
-v ~/web:/var/www/html:ro,ZBind mount with private SELinux label
podman volume create V · -v V:/dataNamed volume
-e NAME=valueSetting
podman unshare ls -ln DIRFiles as the container sees them
podman build -t localhost/app:1 .Build from a Containerfile
podman tag A B · podman history IMAGENames and layers

Service

ItemDoes
~/.config/containers/systemd/NAME.containerQuadlet file
[Container] Image= PublishPort= Volume=What to run
[Service] Restart=always · [Install] WantedBy=default.targetPolicy
systemctl --user daemon-reload · start NAME.serviceGenerate and start
journalctl _SYSTEMD_USER_UNIT=NAME.serviceIts log
sudo loginctl enable-linger USERStart at boot
sudo firewall-cmd --permanent --add-port=8080/tcpLet others in

Flashcards

Pull and list images?
podman pull FULLNAME · podman images
Run a one-off container?
podman run --rm IMAGE command
Run a service container?
podman run -d --name NAME -p 8080:8080 IMAGE
Look at running and stopped containers?
podman ps · podman ps -a · podman logs NAME · podman exec NAME cmd
Stop and remove?
podman stop NAME · podman rm NAME · podman rm -f NAME · podman rmi IMAGE
Publish a port?
-p HOST:CONTAINER (rootless: host port 1024 or higher); allow it in firewalld
Share a host directory?
-v ~/web:/var/www/html:ro,Z (Z = SELinux relabel, private)
Keep data in a volume?
podman volume create V · -v V:/data
Build an image?
Containerfile: FROM, COPY, CMD · podman build -t localhost/name:1 .
Quadlet file?
~/.config/containers/systemd/web.container: [Container] Image= PublishPort= · [Service] Restart=always · [Install] WantedBy=default.target
Start a Quadlet service?
systemctl --user daemon-reload · systemctl --user start web.service
Survive a reboot without a login?
sudo loginctl enable-linger student