3 months ago
Setup:
- Two services in the same project and environment (production): a
Python/FastAPI backend and a Railway-managed PostgreSQL database
- Both services have private networking enabled
- Backend DATABASE_URL points to postgres.railway.internal:5432
- Backend runs alembic upgrade head (database migrations) on startup
before starting the web server
Problem:
The backend container cannot resolve the Postgres private hostname.
Every deploy crashes with:
socket.gaierror: [Errno -2] Name or service not known
DNS debug output from inside the backend container:
resolv.conf:
search internal railway.internal
nameserver fd12::10
Trying to resolve postgres.railway.internal...
IPv6: [Errno -2] Name or service not known
IPv4: [Errno -2] Name or service not known
Any: [Errno -2] Name or service not known
The Railway internal DNS nameserver (fd12::10) is configured in
resolv.conf but returns no records for the Postgres service hostname on
any address family.
What I've tried (all failed):
1. Multiple redeploys of the backend service
2. Redeploying the Postgres service, then the backend
3. Renaming the Postgres private hostname (e.g. postgres → db),
redeploying Postgres, then redeploying the backend with updated URL
4. Renaming back to postgres, redeploying Postgres, then backend
5. Adding a DNS retry loop with backoff in the startup script (retries
5 times over 15 seconds — never resolves)
What changed:
This was previously working with a public proxy URL. I removed the
public proxy on the Postgres service to use private networking only.
Since then, the private hostname has never resolved.
Container info:
- Base image: python:3.12-slim
- The DNS debug runs Python's socket.getaddrinfo() directly — same
resolution path the database driver (asyncpg) uses
2 Replies
Status changed to Awaiting Railway Response Railway • 3 months ago
0x5b62656e5d
Are you doing this during the build phase or the deploy phase?
3 months ago
Additional info from my side:
The DNS server at fd12::10 is reachable from the backend container, but returns no records for the Postgres hostname. Tried postgres, Postgres, postgres.railway.internal, and Postgres.railway.internal. None resolve on any address family. The DNS server is up but has no entry for the database service.
Answer to your question:
Deploy phase. My Dockerfile only installs dependencies. The migration command runs in start.sh via CMD ["bash", "start.sh"]. This is the container's runtime entrypoint, not a build step. The DNS debug output I shared also runs at deploy time and confirms the DNS server is reachable but returns no records.
Status changed to Solved nick-tenderpulse • 3 months ago