Skip to content

Managing Podman Containers on Centos 8 with Podman-generate-systemd and Systemd

Posted on:December 8, 2022 at 08:31 PM

Managing Podman Containers on Centos 8 with Podman-generate-systemd and Systemd

Centos 8 is a popular Linux distribution that is known for its stability and security. One of the key features of Centos 8 is the ability to run containers using Podman. In this post, we will look at how to manage Podman containers using podman-generate-systemd and systemd.

Introduction to Podman and Systemd

Podman is a tool for managing containers that is built on top of the libpod library. It allows users to create, run, and manage containers in a safe and efficient way. Unlike traditional container engines like Docker, Podman does not require a daemon to run, which makes it more secure and efficient.

Systemd is a system and service manager for Linux systems. It is responsible for starting, stopping, and managing services and other system components. Systemd is the default init system for Centos 8, which means that it is used to manage the services and processes that run on the system.

Installing Podman and Systemd on Centos 8

Before we can start using Podman and Systemd to manage our containers, we need to install them on our Centos 8 system.

To install Podman, we can use the yum package manager. First, we need to enable the PowerTools repository, which contains the Podman package:

sudo yum install -y epel-release
sudo yum config-manager --set-enabled PowerTools

Once the repository is enabled, we can use yum to install Podman:

sudo yum install -y podman

Systemd is already installed on Centos 8 by default, so there is no need to install it.

Managing Podman Containers with Systemd

Once we have installed Podman and Systemd, we can start using them to manage our containers. The first step is to create a systemd service file for our container.

To do this, we can use the podman-generate-systemd command. This command takes the name of the container and the name of the service file as arguments, and generates a systemd service file for the container. For example, to generate a service file for a container named my-container, we can use the following command:

sudo podman-generate-systemd my-container > my-container.service

This will create a my-container.service file in the current directory. This file contains the necessary information for systemd to manage the container, such as the command to start and stop the container, the dependencies, and the environment variables.

Once we have created the service file, we can use the systemctl command to manage the container. For example, to start the container, we can use the following command:

sudo systemctl start my-container

To stop the container, we can use the stop subcommand:

sudo systemctl stop my-container

We can also use the enable and disable subcommands to enable or disable the container to start automatically at boot time:

sudo systemctl enable my-container
sudo systemctl disable my-container

Finally, we can use the status subcommand to check the status of the container:

sudo systemctl status my-container

Conclusion

In this post, we looked at how to manage Podman containers on Centos 8 using podman-generate-systemd and Systemd. We saw how to install Podman and Systemd, how to generate a systemd service file for a container, and how to use systemctl to manage the container.

By using Podman and Systemd together, we can easily and efficiently manage our containers on Centos 8. This allows us to take advantage of the benefits of containers, such as portability and isolation, without the need for a daemon like Docker.

Overall, using Podman and Systemd is a powerful and secure way to manage containers on Centos 8.