CONTAINERS AS SERVICES USING PODMAN ON RHEL/CENTOS 8

Ferchichi Wissem
1 min readMar 24, 2021

Podman (Pod Manager) is a fully-featured container engine that is a simple daemonless tool. Podman provides a Docker-CLI comparable command line that eases the transition from other container engines and allows the management of pods, containers, and images.

With systemd initialization service we can manipulate pods and containers, with podman generate system we can generate systemd unit file for containers and pods.

With systemd unit files, we can :

  • Set up a container or pod to start as a systemd service.
  • Define the order in which the containerized service runs and check for dependencies (for example making sure another service is running, a file is available or a resource is mounted).
  • Control the state of the systemd system using the systemctl command.

Procedure :

  • Enable users to start a service at system start and persist over logouts, with : loginctl enable-linger <username>
  • Start a service at user login and stop it at user logout, with : systemctl — user enable <service>

1- Generating a systemd unit file using Podman :

  • Create a container :
$ podman create -d --name mariadb registry.access.redhat.com/mariadb:latest 
  • Use the container name or ID to generate the systemd unit file and direct it into the ~/.config/systemd/user/container-mariadb.service file:
$ podman generate systemd --name mariadb > ~/.config/systemd/user/mariadb.service

2- Auto-starting containers using systemd :

  • Reload systemd manager configuration :
# systemctl --user daemon-reload
  • Enable the service container-mariadb.service and start it at boot time:
# systemctl --user enable container-mariadb.service
  • Start the service immediately:
# systemctl --user start container-mariadb.service

--

--