Podman - Compose

Over the last weekend, I was hanging around in the Podman Matrix chat and was seeing lots of conversation regarding Podman and Docker Compose. So, let's dig into Podman Compose and why you don't need a Kubernetes Cluster/Instance for Container orchestration.

Podman - Compose

Over the last weekend, I was hanging around in the Podman Matrix chat and was seeing lots of conversation regarding Podman and Docker Compose. So, let's dig into Podman Compose and why you don't need a Kubernetes Cluster/Instance for Container orchestration.

Docker Compose

Most of you may know Docker Compose. It is a functionality to describe a multi-container deployment in a YAML file. In the best case, you will have a single file that deploys an application, a database server, all volumes and maybe a bit more. Starting and stopping the same is pretty easy, too.

The Docker developers have provided this functionality for complex deployments on simple infrastructure. So, what does this mean? In case you are having a single machine (like a home server), you don't want to have a complex Kubernetes setup, but you also don't want to spin up each container in correct order manually. Docker Compose is made for exactly this scenario.

The developer also provided a very useful specification for the YAML file, which is easy to understand and well described.

Podman Compose

When it comes to Podman, there was no compose feature for quite some time. Instead, Podman was focusing on systemd integration and playing Kubernetes files. Both are awesome ways to deploy containers, but Docker Compose is very well known and public in the community.

Anyway, due to some community effort, podman-compose was made and is now part of the containers project. It is an implementation of Docker Compose for Podman and also takes care of the rootless part.

So, let's see how this works.

Hint
The guide is tested on Fedora 35 with Podman 3.4.4 and podman-composer 1.0.3.

Install

Since Podman Compose is not part of the standard Podman installation, you need to install it. For Fedora, this is quite easy:

# Install Podman Compose
$ sudo dnf install podman-compose -y

But, if you like the Python way more, you can also install podman-compose in a virtual environment via pip.

# Install via Pip
$ pip install podman-compose

That's already it, now we can have a look at the deployments.

Project

If you want to find some projects on your own to play with Podman Compose, I suggest having a look at "awesome-compose". It's a nice collection of prepared compose files to start with. I have opted for something I have absolutely no use for: WordPress. It's a content management system, that can be used to publish your own websites and blogs.

The provided example from awesome-compose is my starting point.

Creating the file

Just copy the content from the example and put it in a "compose.yml" file. I have edited the example slightly for this blog and to make it running rootless on Fedora.

---
services:

  wordpress:
    image: docker.io/library/wordpress:latest
    ports:
      - 8080:80
    restart: always
    environment:
      - WORDPRESS_DB_HOST=db
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=password
      - WORDPRESS_DB_NAME=wordpress

  db:
    image: docker.io/library/mariadb:10.6.4-focal
    command: '--default-authentication-plugin=mysql_native_password'
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=somewordpress
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=password
    expose:
      - 3306
      - 33060

volumes:
  db_data:
compose.yml

This will do the following:

  • start a WordPress container and publish port 8080/TCP
  • start a MariaDB container and expose the ports to the container network
  • map a named volume to the database container

In case you want to know more about Podman Networking or Volumes, I recommend start with this and this article.

Starting everything

So, now we want to start the whole thing. It's as easy as firing a single command.

# Start the deployment
$ podman-compose up

This will download the images, start everything and create the needed resources. After a minute, you can check if everything is running as expected. Be aware, that the command will run in foreground and you need to open another terminal to enter the below commands.

# Check containers
$ podman ps -a
CONTAINER ID  IMAGE                                   COMMAND               CREATED        STATUS                 PORTS                 NAMES
785a4567a346  docker.io/library/wordpress:latest      apache2-foregroun...  5 minutes ago  Up About a minute ago  0.0.0.0:8080->80/tcp  temp_wordpress_1
27886e8b1e7e  docker.io/library/mariadb:10.6.4-focal  --default-authent...  5 minutes ago  Up 5 minutes ago                             temp_db_1

# Check networks
$ podman network ls
NETWORK ID    NAME          VERSION     PLUGINS
2f259bab93aa  podman        0.4.0       bridge,portmap,firewall,tuning
6bcff8bdedde  temp_default  0.4.0       bridge,portmap,firewall,tuning,dnsname

# Check volumes
$ podman volume ls
DRIVER      VOLUME NAME
local       5d3d21ee508df9ecf6c148cd5cbc845dfaa1b6757bc3b1038fec7d7e78e543db
local       temp_db_data

As you can see, Podman Compose has created a bunch of stuff. Pointing your browser to localhost:8080 will also present a web page like the below:

And there we go with our first Podman Compose deployment.

Alternatives

Using Podman Compose is meant for fast deployment setups and experimenting. There are better options to deploy containers for production ready environments. The below list provides some examples for the same:

Furthermore, you can use Docker Compose with Podman, which will be addressed in a future article. For now, I will add some useful links for these topics in the next section.

GitHub - containers/podman-compose: a script to run docker-compose.yml using podman
a script to run docker-compose.yml using podman. Contribute to containers/podman-compose development by creating an account on GitHub.
Manage containers with Podman Compose - Fedora Magazine
Learn how to manage pods and containers using the podman-compose command, which doesn’t require a daemon or root privileges.
Using Podman and Docker Compose
Podman 3.0 now supports Docker Compose to orchestrate containers.
Compose specification
Compose file reference

Conclusion

Podman Compose is a nice option to test and use Docker Compose features with Podman. It is not as feature complete or versatile as Docker Compose, but still a nice community project. How do you compose your containers?