databasepostgresqldockergodocker-multi-stage-build

Cannot connect to the database Postgres Docker Container from other Container


I have a service in a Docker Container, which synchronies Data from an another DB to my DB and the Sync-Container can't get a connection to the Postgres DB Container.

The Containers It restarts because it exits after every connection failure

My Error-Message

Cannot connect to the database, exiting now: dial tcp 127.0.0.1:5432: connect: connection refused"

I can connect to the DB via TablePlus on 127.0.0.1:5432 but via Docker Inspect is Docker Inspect on IP Adress

The Sync-Service is Written in Go - Database Name, User and Password are the same as I connected via TablePlus. I also tried the IPs 0.0.0.0 and the 172.19.0.2.

Does anyone have any idea why its not connecting?


Solution

  • Try connecting to postgres:5432

    You need to use container name when connecting from another docker container