Cannot Access FastAPI Service from Public Network

elvis339
PRO

24 days ago

Our FastAPI service starts successfully on Railway but is not accessible from the public internet, getting 503 after 10s.

The container logs show the server is running correctly.

Environment:

  • Python 3.11-slim-bullseye Docker image

  • Hypercorn ASGI server

  • FastAPI application

  • Service URL: https://ollie-production.up.railway.app

Dockerfile:

FROM python:3.11-slim-bullseye

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app

WORKDIR /app

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        build-essential \
        curl \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .

RUN pip install --no-cache-dir --upgrade pip \
    && pip install --no-cache-dir -r requirements.txt

COPY ./src ./src

RUN useradd --create-home --shell /bin/bash app \
    && chown -R app:app /app
USER app

EXPOSE ${PORT:-8080}

CMD ["sh", "-c", "hypercorn src.main:app --bind 0.0.0.0:${PORT:-8080} --debug"]

Container Logs (Success):

Starting Container
INFO:asyncio:<Server sockets=(<asyncio.TransportSocket fd=3, family=2, type=1, proto=0, laddr=('0.0.0.0', 8080)>,)> is serving
[2025-07-12 11:30:43 +0000] [4] [INFO] Running on http://0.0.0.0:8080 (CTRL + C to quit)
INFO:hypercorn.error:Running on http://0.0.0.0:8080 (CTRL + C to quit)

Issue:

  • Container starts successfully and binds to port 8080

  • Server shows as running in logs

  • Public URL https://ollie-production.up.railway.app is not accessible (connection timeout/refused)

  • Health check endpoint /health exists in the application and it's a successful call after the build

What we've tried:

  • Binding to 0.0.0.0:${PORT}

  • Using both uvicorn and hypercorn

  • Verified FastAPI routes are defined correctly

  • Confirmed container is running without errors

Solved

2 Replies

Railway
BOT

24 days ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


elvis339
PRO

24 days ago

Fixed it by changing the port to 8080 in Public Networking

The main confusion was the successful /health returning 200.


Status changed to Solved brody 24 days ago


Cannot Access FastAPI Service from Public Network - Railway Help Station