Dim-Jones Blog
Back to blog

Using Docker Compose with Podman

3 min read

Docker Compose is a powerful tool for defining and running multi-container Docker applications. However, you might prefer using Podman, a daemonless container engine, instead of Docker. This guide shows how to use Docker Compose with Podman on CentOS 9, covering both root and non-root user setups.

Using Docker Compose as a Root User

Way 1: Using Docker Compose Itself

This method uses Docker Compose (an independent Go-based tool) to run compose files directly with Podman.

Step 1: Install podman-docker

The podman-docker package provides a Docker CLI compatibility layer for Podman. It symlinks or mimics Docker CLI commands to Podman.

On CentOS 9, install it with:

sudo dnf install -y podman-docker

Step 2: Install Docker Compose

Download the latest Docker Compose version from the official GitHub releases page:

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

Make the binary executable:

sudo chmod +x /usr/local/bin/docker-compose

Create a symbolic link to run Docker Compose with sudo:

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Step 3: Start the Podman Socket

Docker Compose requires a Unix socket to communicate. Enable and start the Podman socket:

sudo systemctl enable --now podman.socket
sudo systemctl status podman.socket

Check that the Unix socket is running and linked to the Docker socket by podman-docker:

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

You should see OK in the output, indicating the socket is working.

Step 4: Use Docker Compose

Create a new file called compose.yml with the following content:

services:
  db:
    image: 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=wordpress
    expose:
      - 3306
      - 33060
  wordpress:
    image: wordpress:latest
    ports:
      - 8006:80
    restart: always
    environment:
      - WORDPRESS_DB_HOST=db
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=wordpress
      - WORDPRESS_DB_NAME=wordpress
    depends_on:
      - db
volumes:
  db_data:

In the same directory, run the following command to start the services:

sudo docker-compose up -d

You can now access your WordPress blog at http://ip_address:8006 using your browser.

Using Docker Compose as a Non-Root User

For non-root users, follow these steps to set up Docker Compose with Podman:

Step 1: Enable and Start the Podman Socket

Enable and start the Podman socket for the current user:

systemctl --user enable podman.socket
systemctl --user start podman.socket

Step 2: Configure Docker Host

Set the DOCKER_HOST environment variable to point to the Podman socket. Add the following line to your shell configuration file (~/.bashrc for Bash or ~/.zshrc for Zsh):

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

Reload your shell configuration:

source ~/.bashrc
# or source ~/.zshrc for Zsh

Step 3: Use Docker Compose

You can now use Docker Compose as a non-root user. In the directory with your compose.yml file, run:

docker-compose up -d

This will start the services defined in your compose.yml using Podman, just as you would with Docker.

Conclusion

This guide demonstrated how to integrate Docker Compose with Podman on CentOS 9 for both root and non-root users. By using the compatibility layer provided by podman-docker, you can seamlessly integrate Docker Compose with Podman, benefiting from Podman’s enhanced security features while still using familiar Docker Compose workflows.

Alternative tools include podman-compose, a Python-based project that replicates Docker Compose functionality for Podman users. Additionally, Podman’s native pod concept allows running multiple containers in a shared context, which can simplify managing containerized applications.

Dim-Jones

Dim-Jones

Digital engineering agency specialized in DevOps, software development and AI.

Visit dim-jones.com