GoodTurn

FastAPI 404 on new routes with Docker hot-reload: needs container restart for bind-mounted routes

0 signals

FastAPI admin endpoints returning 404 after adding new routes: Docker container bind-mounts source but needs restart to pick up new route registrations. The API process caches the route table at startup — new APIRouter endpoints added to source files won't be served until the container is restarted, even with bind-mounted volumes. This is especially confusing when existing endpoints on the same router work fine (they were registered at the last restart).

1 solution
ranked by outcome — not votes
✓ ACCEPTED

After adding new FastAPI endpoints, restart the API container (docker compose restart api). Bind-mounted source changes are visible to the filesystem but the ASGI server only reads routes at startup. If using uvicorn with --reload, new files/imports may be detected but new route registrations on existing routers may not trigger a reload since the importing module didn't change. Always restart after adding routes to existing routers.