Docker Compose is an open-source tool used by developers for orchestrating containers locally or in production. If you are new to containers, I suggest checking out the following links:
- Get Started with Docker
- A Practical Introduction to Container Terminology
- Using Pods with Podman on Fedora
- Podman with Capabilities on Fedora
Podman, a powerful alternative to Docker CLI, has attracted a lot of developers recently. However, Podman users faced a challenge. Docker Compose was expected to work with Docker daemon only. So, Podman users had to use other alternatives to Docker Compose like using Podman Compose that runs services defined in the Compose file inside a Podman pod. (To learn more about Podman Compose, check out my article Manage Containers on Fedora with Podman Compose on Fedora Magazine.) Another method was manually running different containers of an application and then generating a Kubernetes file with
Podman and Docker Compose
Both of the Docker Compose alternatives mentioned previously have their limitations. At the least they need you to know a little bit more than Container and Docker basics.The good news is that Podman has added support for Docker Compose since version 3.0 so you can now run your traditional docker-compose.yml files with Podman backend. Podman does this by setting up a UNIX socket for
Install the following packages on your system to run Docker Compose with Podman:
- podman: Tool for managing containers
- docker-compose: Tool for orchestrating containers
- podman-docker: Installs a script named docker that emulates docker CLI using Podman. Also links Docker CLI man pages and podman.
Install the above packages using dnf:
sudo dnf install -y podman podman-docker docker-compose
Setting Up Podman Socket
Set up the Podman socket in order for Docker Compose to work:
sudo systemctl enable podman.socket sudo systemctl start podman.socket sudo systemctl status podman.socket
This sets up a Unix socket in to communicate with Docker Compose and symlinks it to /var/run/docker.sock. To test if you can communicate with the socket, run the following curl command:
sudo curl -H "Content-Type: application/json" --unix-socket /var/run/docker.sock http://localhost/_ping
If the output from the above command is OK, it means your setup was successful.
Running A Sample Project with Docker Compose
Now, you can start orchestrating your project by going to the project folder and running
sudo docker-compose up
If everything goes well, you will see docker-compose bringing up the services defined in the compose YAML file. Access the new WordPress instance at http://localhost:8080 after the containers are created. To stop the project, you can press Ctrl + C in the terminal where you executed docker-compose up. To remove the containers, execute
sudo docker-compose down
Running Docker Compose with Rootless Podman
The setup shown above uses Podman in root-ful mode. Notice the sudo keyword preceding most of the commands used. Often you will not need to run your projects as root. So, having the option to run docker-compose as a regular user is pretty handy. As of version 3.2.0, Podman supports Docker-Compose with rootless Podman. The setup, however, changes as follows:
systemctl --user enable podman.socket systemctl --user start podman.socket systemctl --user status podman.socket export DOCKER_HOST=///run/user/$UID/podman/podman.sock
Note that when starting the podman socket as non-root user, a user-level socket will be created at /run/user/$UID/podman/podman.sock, where $UID refers is the non-root user’s user ID. We need to set the DOCKER_HOST environment variable to that socket so that Docker Compose can talk to the correct socket. You can add the environment variable to your ~/.bash_profile to make it persistent across system reboots. In root-ful mode, the socket is created in /run/podman/podman.sock which is symlinked to /var/run/docker.sock (the default socket expected by the docker-compose binary). So, we didn’t need to set DOCKER_HOST variable then.
Now, in rootless mode, we can simply run the command
without “sudo” in the project root folder. This will bring up our WordPress site running on Docker Compose with Podman backend.