Podman Series: Container as a service

Podman Series: Container as a service

In this hands-on article, we will learn how to create and run a container using Podman as a service. Let's create a web server running on port 8080, attach an HTML home page as a volume, and then run it as a service on Ubuntu..

Step 1: To begin, we will create an Apache HTTP Server (httpd) container. This container will have a home page attached as a volume located at /web and will run on port 8080. This setup will allow us to serve web content through the containerized server.

sudo podman run --name=reg-httpd -d -p 8080:80 -v /web:/usr/local/apache2/htdocs docker.io/httpd

Step 2: After setting up the Apache HTTP Server container in Step 1, the next task involves utilizing podman generate to produce a systemd configuration. This configuration will help manage the container effectively within the system environment, ensuring smooth operation and integration with other services. By generating this configuration, we enhance the container's functionality and streamline its interaction with the host system.

podman generate systemd reg-httpd | sudo tee -a /usr/lib/systemd/system/reg-httpd.service

Here is the sample out of above command

Generated systemd service unit file for reg-httpd container:
------------------------------------------------------------

[Unit]
Description=Container for reg-httpd
After=network.target

[Service]
Restart=always
ExecStart=/usr/bin/podman run --conmon-pidfile /var/run/podman/podman.pid --cidfile /var/run/podman/podman-container-reg-httpd.cid --cgroups=no-conmon --systemd-cgroups --tmpfs /run --tmpfs /tmp --security-opt label=disable --rm --name reg-httpd -p 80:80 -p 443:443 -v /var/www/html:/var/www/html:Z -v /etc/httpd/conf:/etc/httpd/conf:Z -v /etc/httpd/conf.d:/etc/httpd/conf.d:Z -v /etc/httpd/certs:/etc/httpd/certs:Z -d reg-httpd:latest

[Install]
WantedBy=multi-user.target

Step 3: configure system configuration

sudo systemctl daemon-reload
sudo systemctl enable --now reg-httpd.service
systemctl status reg-httpd.service

podman generate systemd command facilitates the seamless integration of containerized applications into the Linux system's service management framework, leveraging the capabilities of systemd to ensure reliable, consistent, and efficient operation of containerized services.