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.
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.
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.
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.
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.
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
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
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.
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:
- k3s (Kubernetes for single instances)
- Minikube (for Kubernetes development)
- Podman - systemd managed containers (for production)
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.
Links & Docs
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?