Application failed to respond - Django
teekayjota
PROOP

2 years ago

Details:

  • Environment: I’m using a Python 3.12-slim Docker image.
  • Application: Django backend served with Uvicorn.
  • Deployment: The app builds successfully, and migrations run without issues. However, when accessing the app, it returns a 502 error.
  • Port Configuration: The PORT variable doesn’t seem to be correctly interpreted within the Docker container. The error logs show that "$PORT" is not being recognized as a valid integer, causing Uvicorn to fail to start.

Steps Taken:

  1. Dockerfile Configuration:
    • I used the recommended Railway Dockerfile setup with Uvicorn, ensuring all necessary dependencies are installed (libpq-dev, gcc, libmariadb-dev, etc.).
    • I’ve tried both setting the PORT directly and using it as an environment variable, but Uvicorn still fails to recognize it.

The app runs but throws a 502 error when accessed, likely due to the incorrect handling of the PORT variable. I need help identifying why the PORT variable isn’t being correctly recognized and ensuring the app runs on the expected port.

Dockerfile:

FROM python:3.12-slim

WORKDIR /app

RUN apt-get update && apt-get install -y \ libpq-dev \ gcc \ libmariadb-dev-compat \ libmariadb-dev \ pkg-config \ && apt-get clean

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD uvicorn main:app --host 0.0.0.0 --port $PORT

Url: https://eucerinv2backend-production.up.railway.app/

Solved

3 Replies

2 years ago

Hi, could you echo $PORT on start, in order to check what's being passed ?

I recommend testing your dockerfile locally to try and reproduce the error.

Please note that you can also just define PORT in your service's env vars, and use a fixed port on boot.

Example: CMD uvicorn main:app --host 0.0.0.0 --port 3200 and PORT=3200 in your service's env.

Docs for this can be found here: https://docs.railway.app/guides/public-networking#port-variable


Status changed to Awaiting User Response Railway almost 2 years ago


teekayjota
PROOP

2 years ago

solved!

changed to: CMD uvicorn eucerinescuela_backend.asgi:application --host 0.0.0.0 --port 8080


Status changed to Awaiting Railway Response Railway almost 2 years ago


2 years ago

amazing 🙌


Status changed to Awaiting User Response Railway almost 2 years ago


Status changed to Solved nico almost 2 years ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...