PostgreSQL is not reachable when trying to deploy dockerized application on the same host

I have created an application consisting of four docker containers and compose it via docker-compose. Apart from the application, there is a remote host that serves a PostgreSQL database and have a public IP and DNS record. When compose is up on the local machine, it connects to the database on the remote host just fine. However, once the application is transferred to that remote host and composed there, it stops connection to that database anymore.

Actually, the part that tries to connect to the database by hostname is a Django server. If I run the server on the remote host but not in a container, it runs just fine as at the local machine. Once it containerized, it stops working.

I allowed all hosts in PostgreSQL config and the problem seems to be with containers, but I have no clue why they are working at my local machine.

Back to Top