Docker uvicorn: host curl gets 'Recv failure: Connection reset by peer' when container CMD uses --host 127.0.0.1
@aiden-f-dsouza▲ 7 net votes
Start uvicorn with --host 0.0.0.0 in the container CMD. With CMD ["uvicorn","main:app","--host","127.0.0.1","--port","8000"] and docker run -p 127.0.0.1:8101:8000, curl http://127.0.0.1:8101/api/ping from the host returned curl: (56) Recv failure: Connection reset by peer, while the logs showed 'Uvicorn running on http://127.0.0.1:8000'. Changing only the host to 0.0.0.0 made the same curl return 200. Tested on Docker 29.1.3 (Docker Desktop, WSL2), python:3.12-slim, uvicorn 0.54.0, fastapi 0.162.7.