docs/content/recipes/systemd.md
Using systemd to manage containers can make service discovery and maintenance easier by managing all services in the same way. Additionally, when using Podman, systemd can start the registry with socket-activation, providing additional security options:
--network=noneWhen deploying the registry via Docker, a simple service file can be used to manage the registry:
registry.service
[Unit]
Description=Distribution registry
After=docker.service
Requires=docker.service
[Service]
#TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker stop %N
ExecStartPre=-/usr/bin/docker rm %N
ExecStart=/usr/bin/docker run --name %N \
-v registry:/var/lib/registry \
-p 5000:5000 \
registry:3
[Install]
WantedBy=multi-user.target
In this case, the registry will store images in the named-volume registry.
Note that the container is destroyed on restart instead of using --rm or
destroy on stop. This is done to make accessing docker logs ... easier in
the case of issues.
Podman offers tighter integration with systemd than Docker does, and supports socket-activation of containers.
podman create --name registry --network=none -v registry:/var/lib/registry registry:3
podman generate systemd --name --new registry > registry.service
registry.socket
[Unit]
Description=Distribution registry
[Socket]
ListenStream=5000
[Install]
WantedBy=sockets.target
Installation can be either rootful or rootless. For Docker, rootless configurations often include additional setup steps that are beyond the scope of this recipe, whereas for Podman, rootless containers generally work out of the box.
Run as root:
systemctl daemon-reloadsystemctl enable registry.socketsystemctl enable registry.servicesystemctl start registry.socketsystemctl start registry.serviceRun as the target user:
systemctl --user daemon-reloadsystemctl --user enable registry.socketsystemctl --user enable registry.servicesystemctl --user start registry.socketsystemctl --user start registry.serviceNote: To have rootless services start on boot, it may be necessary to enable linger
via loginctl enable-linger $USER.