DEV Community

Discussion on: How to easily create a Postgres database in Docker

Collapse
 
kristiannissen profile image
Kristian Nissen

There are a few details that I think would improve your post.

I needed to connect to Postgresql from a different container that runs the code. To do so I needed the IP of the postgres docker, you can get that using the following command

docker inspect [container]

The IP Address can be found in the output looking something like this "IPAddress": "172.17.0.3"

With that I could now create an environment variable for the connection URL

DATABASE_URL=postgres://postgres:docker@172.17.0.3:5432/world?sslmode=disable go run main.go