liveBook · Manning

Socket activation

As explained in Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more

A socket-activated service is a service that is started when a connection arrives on a listening socket and may exit while idle.

Socket activation starts a service only when a connection arrives on a listening IP or UNIX domain socket. The service may exit while idle, and systemd starts it again for a later connection. section 7.6

Systemd owns the listening socket and hands connections to the activated service. For a containerized service, Podman becomes the intermediary that launches the container and passes the connection into it. section 7.6 section 1.3.7

A typical socket-activated Podman workflow is:

  • Stop the service to stop and remove the container; a later connection activates it again. section 7.6

The same design keeps Podman itself non-daemonized. Rootful and rootless podman.socket units listen on their respective UNIX sockets, launch the Podman service for API requests, and allow it to exit after five seconds without activity. section 9.1.1

Enable a rootless Podman socket

systemctl --user enable --now podman.socket ls $XDG_RUNTIME_DIR/podman/podman.sock curl -s --unix-socket $XDG_RUNTIME_DIR/podman/podman.sock http://d/v1.0.0/libpod/version

Figure 7.9 When a connection to the socket systemd is listening on arrives, systemd activates Podman, which launches the container, passing the socket down to the container.

Trace the activation boundary from systemd's listening socket through Podman to the container handling the connection. section 7.6

How Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more covers it

How deep it goes
Explains socket ownership, connection handoff, idle exit, container removal, and rootful or rootless Podman units.
Examples
Demonstrates a localhost HTTP socket, browser-triggered container startup, Podman API probing, and rootless socket commands.
What it assumes
Assumes Linux systemd and basic Podman familiarity while defining socket activation and distinguishing rootful from rootless sockets.
What you can do after
Operate on-demand Podman services through systemd socket units and probe the activated Podman API over a UNIX socket.
How it connects
Connects systemd, Podman services, containers, UNIX domain sockets, REST APIs, rootless operation, and SSH remote connections.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more. The section links point to the parts of the book it draws on.