Getting Started with Podman Compose

Written by: Dwijadas Dey   |   Last updated: March 25, 2024

Podman is a containerization tool that provides a way to manage Open Containers Initiative(OCI) compatible containers on Linux systems. The functionality of podman is similar to Docker. However, the podman operates without requiring a daemon, making it more lightweight and secure. Like Docker, Podman also allows users to create, manage, and run containers using the same commands and interface, making it easy for those familiar with Docker to transition to Podman.

While Docker has "Docker Compose" for managing multi-container applications, no equivalent tool is initially integrated into Podman. Later, the functionality of docker compose was introduced with the release of Podman 3.2. Let's look at how to manage containers run by podman using a tool like docker-compose in the next section.

What is podman-compose?

Podman compose is a tool that lets you manage containers like docker-compose.

It implements compose specification with Podman as the backend. More specifically, podman compose is a light wrapper around an external compose provider like docker-compose. So podman compose executes another tool(docker-compose) that implements the compose functionality. 

In the next section, we will look at installing Podman Compose in Ubuntu 22.04 Jammy Jellyfish.

Install podman-compose

Podman compose needs two packages namely podman-docker and docker-compose. If you have already installed podman then skip the next step and proceed with installing podman-docker and docker-compose.

$ sudo apt install podman

Configure image registries for podman under the section [registries.search] in the configuration file /etc/containers/registries.conf.

…
…
[registries.search]
registries=["registry.access.redhat.com", "registry.fedoraproject.org", "docker.io"]
…
…

Install Docker compose

Download and install Docker compose standalone.

$ sudo curl -SL https://github.com/docker/compose/releases/download/v2.24.7/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

$ sudo chmod 755 /usr/local/bin/docker-compose

$ docker-compose version
check docker compose version

Install Podman Docker

Podman docker is available in the standard Ubuntu repository to get it installed by apt.

$ sudo apt install podman-docker

Now, enable and start Podman docker. This step will create a Unix socket for communication with docker-compose.

$ sudo systemctl enable --now podman.socket
$ sudo systemctl start podman.socket
$ sudo systemctl status podman.socket
podman docker status check

Confirm that the compose functionality is correctly configured to work with docker-compose with the following curl command.

$ sudo curl -w "\n" -H "Content-Type: application/json" --unix-socket /var/run/docker.sock http://localhost/_ping

Install Podman compose

Podman compose is implemented with Python 3. Therefore, you need PIP3 before proceeding with installing Podman Compose. 

$ sudo apt install python3-pip
$ sudo pip3 install podman-compose
$ podman-compose --version
checking podman compose version

Although podman is installed, you may still need to set the correct CNI version in the configuration file(cni) under the user's home directory.  This will enable the podman to create a proper bridge network interface while running the podman compose.

First, check the supported/installed cni version and the filename to be read by podman in the cni config file.

$ cat /etc/cni/net.d/87-podman-bridge.conflist
cni config file

The numbering for the cni config filename may be different in your case. So adjust the config filename accordingly. 

Finally, update the cni version to be used by podman in the filename

~/.config/cni/net.d/ubuntu_default.conflist
update cni version

The installation and environment setup of Podman compose is now complete for any compose provider(e.g. docker-compose) to communicate with the local Podman socket transparently.

Usages of podman compose

To run a few basic podman compose commands, let us create an Apache web container using podman compose. The following docker-compose file defines a service ‘apache’ by specifying the image name, container name, and port mapping.

$ cat <<EOF >docker-compose.yaml
version: '3.9'
services:
  apache:
    image: docker.io/httpd:latest
    container_name: my-apache-app
    ports:
    - '8080:80'
EOF

Start the web application using podman compose. Make sure you are in the same folder as the above docker-compose file.

$ podman-compose up -d

Review the container

$ podman-compose ps
podman compose ps

Test the web service endpoint.

$ curl 0.0.0.0:8080
testing the endpoint

View logs for the services defined in the docker-compose.

$ podman-compose logs apache

To stop all the services specified in the compose file use the following command.

$ podman-compose down

The above command will first stop all the services before deleting the container altogether. 

It is also possible to start/stop/pause services selectively.

$ podman-compose start <service_name>
$ podman-compose stop <service_name>
$ podman-compose restart <service_name>
$ podman-compose pause <service_name>

Where <service_name> is the name of the service defined in the docker-compose file.

Run an ad-hoc command inside the container.

$ podman-compose exec apache ls -l

Get an interactive shell of the container.

$ podman-compose exec apache /bin/bash

These are a few basic podman compose usages to get you started. Navigate to the help pages of podman compose to explore more commands/usages.

$ podman-compose --help
$ podman-compose exec --help

Conclusion

The Podman Compose is an amazing container orchestration tool. From the above discussion, it is evident that Podman Compose aimed to provide a similar interface for users accustomed to Docker Compose, enabling them to define and run multi-container applications using a simple YAML file. Since the development of Podman Compose is ongoing, we may see more functionalities are added to it very often.

About The Author

Dwijadas Dey

Dwijadas Dey

Dwijadas Dey is an open-source software advocate and tech enthusiast. He has been writing blogs about emerging technology for more than 10 years for different cloud service providers and tech sites. He also provides hands-on training and coaching on varied subjects like Kubernetes, Ansible, OpenStack, and Data Streaming.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment