title: Docker compose and postgres official image environment variables
body: <p>Actually I'm using the following docker-compose.yml file</p>
  
  <pre><code>version: '3.3'
  
    services:
      postgres:
        container_name: postgres
        image: postgres:latest
        restart: always
        environment:
          POSTGRES_USER: ${POSTGRES_USER}
          POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
          POSTGRES_DB: ${POSTGRES_DB}
          PGDATA: /var/lib/postgresql/data/pgdata
        ports:
          - "5432:5432"
        volumes:
          - ./data/postgres/pgdata:/var/lib/postgresql/data/pgdata
  </code></pre>
  
  <p>I use also this .env file in the same directory of the docker-compose.yml file:</p>
  
  <pre><code>POSTGRES_USER=dbadm
  POSTGRES_PASSWORD=dbpwd
  POSTGRES_DB=db
  </code></pre>
  
  <p>Then I run a bash shell into container this way:</p>
  
  <pre><code>docker exec -ti postgres bash
  </code></pre>
  
  <p>And after this invoke the command:</p>
  
  <pre><code>psql -h postgres -U dbadm db
  </code></pre>
  
  <p>And I get the error:</p>
  
  <pre><code>psql: FATAL:  password authentication failed for user "dbadm"
  </code></pre>
  
  <p>The strange fact is that if use the default image parameters:</p>
  
  <pre><code>psql -h postgres -U admin database
  </code></pre>
  
  <p>And insert the default password "password", it logs me in, and seems it's ignoring the environment variables.</p>
  
  <p>What am I missing?</p>
  
  <p>Additional logs from docker-compose up logs:</p>
  
  <pre><code>postgres    | 2017-10-15 09:19:15.502 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
  postgres    | 2017-10-15 09:19:15.502 UTC [1] LOG:  listening on IPv6 address "::", port 5432
  postgres    | 2017-10-15 09:19:15.505 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
  postgres    | 2017-10-15 09:19:15.524 UTC [22] LOG:  database system was shut down at 2017-10-15 09:02:21 UTC
  postgres    | 2017-10-15 09:19:15.530 UTC [1] LOG:  database system is ready to accept connections
  </code></pre>
  
  <p>Cannot see any "RUN" line about user, database and password setup.</p>