I'm practicing making a Golang web app that interacts with a PostgreSQL database, each running on their own container.
I'm running the containers with docker-compose up
But I seem to be failing on getting the postgres container properly set up.
For brevity, links to Dockerfiles and other settings files are on this gist (let me know if you want it here instead).
version: '2'
services:
web_app:
build: dockerfiles/web_app
ports:
- "9000:9000"
volumes:
- .:/go/src/gitlab.com/repo/web_app
# links might be replaced by depends_on.
# links:
# - db
depends_on:
- db
# tty and stdin_open cause docker-compose to disconnect from docker-machine after 60sec.
# A fix is on the way.
# tty: true
# stdin_open: true
db:
build: dockerfiles/db
volumes:
- data:/var/lib/postgresql/data
volumes:
data: {}
docker-compose up works fine. But when the application tries to open a database connection with:
var pgConf string = "user=web_app dbname=web_app sslmode=verify-full password=password"
db, err := sql.Open("postgres", pgConf)
I get the following error from docker compose:
Error creating new user: dial tcp [::1]:5432: getsockopt: connection refused
What can I do to make both containers talk to each other?
Thank you in advance.