fastapipodmanpodman-networking

FastAPI curl works inside a container. curl on host machine: Connection reset by peer


I have a FastAPI instance running inside a container.

when I exec bash into it, I can run what's below and it works:

root@974b874a42eb:/code# curl http://localhost:9090
{"id":"e80c3468-d6c7-442c-9de4-cc74d4ea1c1f","ts":"2024-07-10T23:44:52.608550+00:00"}root@974b874a42eb:/code#

when I run the same thing from the host machine I get:

j@fedora:~/Projects$ curl http://localhost:9090
curl: (56) Recv failure: Connection reset by peer

the run command is:

podman run -d -p 9090:9090 -v ./app:/code/app:rw -v ./tests:/code/tests:rw --cap-add=ALL --rm --name ${LOCAL_NAME} ${LOCAL_NAME}

the start command is:

CMD ["fastapi", "dev", "/code/app/main.py", "--port", "9090", "--host", "0.0.0.0", "--reload"]

I would imagine the main culprit would have been only listening to localhost but you can see what I set --host to.

also its an unprivileged port

also I believe this worked before as expected a month ago on a different version of podman.

how can I fix it so that I can expose fastapi correctly to the host machine or any other client?


Solution

  • For some reason localhost fails:

    curl http://localhost:9090
    

    However when I try:

    curl http://127.0.0.1:9090
    curl http://0.0.0.0:9090
    

    both of those work, not sure why.