How to use docker compose with Podman on Linux

Introduction

Using docker compose with Podman on Linux is a straightforward process, especially because Podman is designed to be a drop-in replacement for Docker. This means you can use Podman to run software that was written for Docker, such as Docker Compose, without modifying the Dockerfile or docker-compose.yml files.

Setting up Docker Compose with Podman

Here’s a step-by-step guide to using docker-compose with Podman on Linux:

1. Install Podman

First, ensure that Podman is installed on your system. You can install Podman using your package manager. For example, on Ubuntu:

sudo apt update
sudo apt install -y podman

On Fedora or CentOS:

sudo dnf install -y podman

2. Install Docker Compose

You also need Docker Compose. Install it using pip:

sudo pip3 install docker-compose

3. Set Up Podman to Mimic Docker

You need to configure Podman to mimic Docker. This involves setting up alias and ensuring that socket files are correctly handled.

You can alias Docker commands to Podman for your user by adding the following line to your ~/.bashrc or ~/.zshrc:

alias docker=podman

After adding the alias, apply the changes:

source ~/.bashrc  # or ~/.zshrc

4. Configure Docker Compose for Podman

To make Docker Compose use Podman, and point to the DOCKER_HOST environment variable to Podman’s socket. You can do this on the fly or by setting it permanently in your shell configuration file:

export DOCKER_HOST=unix:///run/user/$(id -u)/podman/podman.sock

For permanent configuration, add the above line to your ~/.bashrc or ~/.zshrc.

5. Run Docker Compose

Now, you can use Docker Compose as you normally would:

docker-compose up

or if you have not aliased docker to podman, you can explicitly tell Docker Compose to use Podman:

DOCKER_HOST=unix:///run/user/$(id -u)/podman/podman.sock docker-compose up

6. Troubleshooting

If you encounter permissions issues with the Podman socket or other related errors, make sure that your user is in the appropriate group to manage Podman containers, and check that the socket path in DOCKER_HOST is correct.

7. Consider Podman Compose

Podman team has developed podman-compose which is a script to help Podman manage full application lifecycles using docker-compose format. It might be beneficial to use podman-compose if you face any compatibility issues:

pip3 install podman-compose

Then use it similarly to Docker Compose:

podman-compose up
How to use docker compose with Podman on Linux

Conclusion

This guide should help you set up a working environment using Podman and Docker Compose on a Linux system. I hope will this your helpful. Thank you for reading the DevopsRoles page!

, ,

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.