Quantcast
Viewing all articles
Browse latest Browse all 14069

FastAPI (uvicorn) + Docker ignores specified host

I need to run a FastAPI in Docker on the remote machine and make it accessible for curl requests from any machine. Container builds and uvicorn starts, but when I try to do a curl request I get connection errors. I've already specified host 0.0.0.0 in the parameters, but experimenting with different ports I've noticed that port param seems to be ignored on uvicorn start. Probably that happens to the host param as well. I don't face this issue when running in the same way locally, at least I get Uvicorn running on http://0.0.0.0:some_port (Press CTRL+C to quit) in local logs.

Dockerfile

ARG PYTHON_VERSION=3.11-slim-busterFROM python:${PYTHON_VERSION} as pythonWORKDIR /appADD . .RUN pip install -r requirements.txtCMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8501"]

docker-compose.yml

version: '3.5'services:  container-name:    container_name: container-name    build:      context: .      dockerfile: Dockerfile    env_file:      - ./env/demo.env          ports:      - "8501:8501" 

docker compose down && docker-compose build --no-cache && docker compose up

...container-name  | INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)...

What could be a problem and what can I try to resolve it?


Viewing all articles
Browse latest Browse all 14069

Trending Articles