title: Cant connect to postgres (password authentication failed for user - docker)
body: <p>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:</p>
  
  <p><a href="https://i.stack.imgur.com/ZB7bP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZB7bP.jpg" alt="enter image description here"></a></p>
  
  <p>Initially, I was trying to connect to postgres with this instruction:</p>
  
  <pre><code>db, err = gorm.Open("postgres", "host=db port=5432 user=sigbrian password=example sslmode=disable")
  </code></pre>
  
  <p>With this docker-compose file:</p>
  
  <pre><code>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"
  </code></pre>
  
  <p>But when I comment the postgres user, database and password environment variables from the file, and try to make the connection this way: </p>
  
  <pre><code>db, err = gorm.Open("postgres", "host=db port=5432 user=postgres sslmode=disable")
  </code></pre>
  
  <p>Still throws the same error. I appreciate any help.</p>