I was trying to run docker compose to set up nginx, golang server and postgresql. The problem is that I can't connect to the database:
Initially, I was trying to connect to postgres with this instruction:
db, err = gorm.Open("postgres", "host=db port=5432 user=sigbrian password=example sslmode=disable")
With this docker-compose file:
version: '3.2'
# volumes:
# database_data:
# driver: local
services:
db:
image: postgres
restart: always
environment:
- POSTGRES_DB:sigdb
- POSTGRES_USER:sigbrian
- POSTGRES_PASSWORD:example
ports:
- '5432:5432'
# volumes:
# - database_data:/var/lib/postgresql/data
golang-app:
build:
context: .
dockerfile: Dockerfile
# command: ["./wait-for-it.sh", "db:5432"]
# ports:
# - '80:8888'
expose:
- '8080'
depends_on:
- "db"
links:
- "db"
nginx-proxy-and-webserver:
image: nginx:1.15.5-alpine
ports:
- '80:80'
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./static:/var/www/sig/static
depends_on:
- "golang-app"
links:
- "golang-app"
But when I comment the postgres user, database and password environment variables from the file, and try to make the connection this way:
db, err = gorm.Open("postgres", "host=db port=5432 user=postgres sslmode=disable")
Still throws the same error. I appreciate any help.