podmanpodman-compose

podman and multiple instances of a service


I have an app with multiple back instances. it works as expected with docker-compose, but when using podman-comose it fails, as it tries to start all the backs in the same port of the pod. in docker this does not happen.

Here is a small example to reproduce my problem :

docker-compose.yml:

version: '3.7'

services:
  back:
    build:
      context: .
    scale: 2

  other-back:
    build:
      context: .

Dockerfile:

FROM python:slim

RUN pip install flask

COPY . .

EXPOSE 5000

CMD flask --app main run --host=0.0.0.0

main.py:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"

in podman compose, all 3 backs are in the same host (127.0.0.1), and tries to listen at port 5000, so only one succeeds. in docker, they are at different hosts, so they can be addressed separately (port 5000 in all of them).

how can i make this example work as intended in podman, as in works in docker?


Solution

  • Aha - it's the docker-compose part you are asking about.

    Short answer - you don't.

    Podman's model isn't quite the same as docker's. As you have noticed the pod is a single network address meaning you get a clash on the ports.

    The "orchestrate pods" part is handled by kubernetes or minikube or similar in the podman model. Rather than having its own in-between system it goes straight from single container to production system.

    Aside: The "drop in replacement for docker" is sort-of true if you don't look too closely. But it's never going to be 100% identical or it would just be docker. The two areas that you'll almost inevitably bump into issues is docker images assuming root privileges and network stuff with compose.

    Aside2: If I was doing this with a home-lab or something of the sort I'd probably use podman's systemd integration and "instantiated services".