Connecting From Django To Postgres When They Are In Different Networks¶
I have 2 different projects, running them using docker compose. I needed to connect from project1.django to project2.postgres. Here is how I did it...
1. Check the running docker containers¶
2. Check the networks¶
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
9eb5f04cf191 project2_default bridge local
92f90ca252de project1_default bridge local
3. Connect project1 Containers to project2_default: First, ensure project2 is up and running so that project2_default network is available.¶
Then, manually connect project1's django container to project2_default network:
4. Ensure that you change the environment variable¶
- Now we are able to connect from project1.django to the project2.postgres