9 days ago
Hey — running into a weird recurring issue and wondering if anyone's seen this.
My backend service is a FastAPI + uvicorn app on Hobby tier (us-east4-eqdc4a). Yesterday I migrated from Nixpacks to a Dockerfile-based build (Playwright base image: mcr.microsoft.com/playwright/python:v1.59.0-jammy).
Since then, every git push has the same pattern:
- Build phase succeeds
- Container starts, alembic migrations run, uvicorn binds to
0.0.0.0:$PORT - Deploy logs show internal
/healthreturning 200 - But Railway's edge returns
{"status":"error","code":502,"message":"Application failed to respond"}until I click⋮ → Redeployfrom the dashboard - After the manual redeploy, the edge starts routing correctly and the app works for hours
It's happened on 3 separate pushes now (Step 1 Dockerfile switch, Step 2 endpoint addition, and a revert). Each time, manual redeploy fixes it.
Has anyone seen this where the edge router doesn't pick up a freshly-deployed container until a manual redeploy? Is there something in my Dockerfile or railway.toml that could be causing it?
Dockerfile is minimal — just FROM ..., WORKDIR /app, COPY requirements.txt + pip install, COPY . ., and CMD ["sh", "-c", "alembic ... && uvicorn main:app --host 0.0.0.0 --port $PORT"]. railway.toml has builder = "DOCKERFILE", dockerfilePath = "backend/Dockerfile", healthcheckPath = "/health".
Any pointers appreciated.
Pinned Solution
8 days ago
Try to decouple your database migrations from your web server startup. I suggest you move your alembic command from CMD in your Dockerfile and make it a pre-deploy command. It could be the reason for delaying your web server from binding to a port and causing the 502 error.
2 Replies
Status changed to Open Railway • 9 days ago
8 days ago
Try to decouple your database migrations from your web server startup. I suggest you move your alembic command from CMD in your Dockerfile and make it a pre-deploy command. It could be the reason for delaying your web server from binding to a port and causing the 502 error.
darseen
Try to decouple your database migrations from your web server startup. I suggest you move your alembic command from `CMD` in your Dockerfile and make it a pre-deploy command. It could be the reason for delaying your web server from binding to a port and causing the 502 error.
2 days ago
Solved. Thank you!
Status changed to Solved brody • 2 days ago