Django Docker container unable to connect to Supabase PostgreSQL: Network is unreachable
I'm working on a Django project with Docker, and I'm trying to connect to a Supabase PostgreSQL database. On my local machine, I can connect to the database using the psql command, but when I try to connect from inside the Docker container, I get the following error:
connection to server at "db.*********.supabase.co" (2a05:d012:42e:5700:63e9:906e:3eeb:5874), port 5432 failed: Network is unreachable
Is the server running on that host and accepting TCP/IP connections?
Request Method: POST
Request URL: http://13.60.86.154:8000/api/user/register/
Django Version: 4.2.20
Exception Type: OperationalError
Exception Value:
connection to server at "db.*********.supabase.co" (2a05:d012:42e:5700:63e9:906e:3eeb:5874), port 5432 failed: Network is unreachable
Is the server running on that host and accepting TCP/IP connections?```
What I’ve tried:
I can connect to the database from my local machine using psql, but not from within the Docker container. The Docker container is running and listening on ports 8000 (backend) and 3000 (frontend) with docker-compose. The error indicates that the connection is being refused because of a "network unreachable" issue. I’ve checked if Docker containers are using IPv6 (the IP shown is an IPv6 address), but the issue persists.
What could be causing this issue? How can I resolve it?