liveBook · Manning

Chapter 7: Integration with systemd

What you will learn in chapter 7 of Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more

The introduction explains why Podman works well with systemd for managing containerized services and previews the integrations covered in the chapter.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why Podman works well with systemd for managing containerized services and previews the integrations covered in the chapter.

Key terms: fork/exec model, scope, cgroup hierarchy, PID cgroup, client-server methodology, systemd unit files, service files, Podman commands, systemd, journald

7.1 Running systemd within a container

This section contrasts single-service containers with containers that run systemd, explains why an init process matters, and identifies when Podman enters systemd mode.

Key terms: microservice, PID 1, systemd unit files, multiservice application, stdout, stderr, SIGCHLD, exit status, zombie process, --init

7.1.1 Containerized systemd requirements

This section explains how Podman prepares a nonprivileged container so systemd can start without mounting filesystems itself.

Key terms: systemd, tmpfs, /run, /tmp, CAP_SYS_ADMIN, entry point

7.1.2 Podman container in systemd mode

This subsection shows how to inspect a Podman container’s systemd-mode environment and stop a container running systemd.

Key terms: --systemd=always, systemd mode, PID1, tmpfs, /run, /tmp, ubi8-init, StopSignal, 37, SIGRTMIN+3

7.1.3 Running an Apache service within a systemd container

This section builds and runs an Apache image with systemd inside the container, then shows how that setup changes where to find service logs.

Key terms: Containerfile, ubi8-init, httpd, dnf, systemctl enable httpd.service, my-systemd, podman build, --p 8080:80, -v ./html/:/var/www/html:Z, index.html

7.2 Journald for logging and events

Introduces journald as Linux’s logging service and explains why Podman uses it by default.

Key terms: systemd journal, journald, log rotation

7.2.1 Log driver

This section explains how Podman log drivers affect log retention and rotation, and shows how to select and check the journald driver.

Key terms: journald, file driver, rootless, systemd, stdout, stderr, journald driver, k8s-file driver, log rotation, log_driver

7.2.2 Events

This section explains how Podman records container lifecycle events and why journald is often preferable to a file for storing them.

Key terms: Podman events, Podman info, events_logger, containers.conf, file event logger, $XDG_RUNTIME_DIR, rootless users, tmpfs, journald, rotation

7.3 Starting containers at boot

This section introduces why boot-time containerized services need systemd when Podman runs without a daemon.

Key terms: daemon, boot time, systemd, container images, systemd service unit files, containerized services

7.3.1 Restarting containers

This section explains how Podman restart policies and systemd services restart containers, including after a reboot, and why systemd unit files offer another approach.

Key terms: podman run, --restart, restart policy, systemd, --restart=always, podman-restart.service, rootful, rootless, systemd service unit file

7.3.2 Podman containers as systemd services

This section shows how to manage an existing Podman container as a systemd service, why detached runs can cause trouble, and how generated unit files help.

Key terms: systemd unit file, conmon, container processes, exit code, podman run --detach, service, podman generate systemd, myapp.service, ExecStart, ExecStop

7.3.3 Distributing systemd unit files to manage Podman containers

This section shows how `podman generate systemd --new` produces unit files that create, stop, and remove containers, making a containerized service distributable to other machines.

Key terms: podman generate systemd, --new, ExecStart, ExecStop, ExecStopPost, --cidfile, myapp-new.service, systemctl, pull the image, auto-update

7.3.4 Automatically updating Podman containers

This section shows how Podman and systemd can detect updated container images, recreate services, and run updates unattended.

Key terms: auto-update, container registry, edge computing, io.containers.autoupdate=registry, podman generate systemd --new, daemon-reload, podman auto-update, ExecStopPost, podman stop, podman rm

7.4 Running containers in notify unit files

This section explains how systemd notify units wait for a containerized service to become ready, how Podman passes the notification socket into the container, and how failed readiness checks can trigger rollback after an update.

Key terms: notify, sd-notify, systemd, NOTIFY_SOCKET, systemd socket, volume mount, Podman auto-update, rollback

7.5 Rolling back failed containers after update

The section explains how Podman rolls back a failed auto-update and introduces socket activation as another way systemd can manage containers.

Key terms: sd-notify, notify socket, podman auto-update, rollback, systemd, container orchestrator, socket activation, unit file

7.6 Socket-activated Podman containers

This section explains how systemd can start a Podman container on demand when a connection arrives at a socket, rather than keeping the service running while idle.

Key terms: systemd, socket-activated services, IP sockets, UNIX domain sockets, Podman, myapp.socket, podman.socket, podman.service, containerized services

7.7 Summary

The summary recaps how Podman integrates with systemd and journald to run services, manage containers, and handle logs and events.

Where this is used later

Concepts explained in this chapter

← Chapter 6: Rootless containers Chapter 8: Working with Kubernetes →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.