postgres and docker-compose : can't create a custom role and database : <p>I'am trying to create a simple postgreSQL container with a custum user and database. </p>

<p>This is my docker-compose file : </p>

<pre><code>version: '2'
services:
  db.postgres:
    container_name: db.postgres
    image: postgres:10
    environment:
      - POSTGRES_USER:'myuser'
      - POSTGRES_PASSWORD:'myuserpassword'
      - POSTGRES_DB:'mydb'
    ports:
      - '5432:5432'
    volumes:
      - ./pgdata:/var/lib/postgresql/data
</code></pre>

<p>And the error when I try to connect to my database. </p>

<pre><code>docker exec -it db.postgres psql -U myuser myuserpassword
psql: FATAL:  role "myuser" does not exist
</code></pre>

<p>OR</p>

<pre><code>$ docker exec -it db.postgres /bin/bash
root@1a0531e0350f:/# psql -U myuser
psql: FATAL:  role "myuser" does not exist
</code></pre>

<p>Docker-compose environment variables appear to be ignored when creating the database.</p>

<p>I don't known what can I do. Do you have an idea of ​​the problem?</p>

<p>Thanks ! </p>
