postgres and docker-compose : can't create a custom role and database

无人久伴 提交于 2019-12-05 21:15:29

问题


I'am trying to create a simple postgreSQL container with a custum user and database.

This is my docker-compose file :

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

And the error when I try to connect to my database.

docker exec -it db.postgres psql -U myuser myuserpassword
psql: FATAL:  role "myuser" does not exist

OR

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

Docker-compose environment variables appear to be ignored when creating the database.

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

Thanks !


回答1:


Modify your docker-compose.yml file as below:

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

Then drop your current data entirely and re-run docker-compose up.



来源:https://stackoverflow.com/questions/49112545/postgres-and-docker-compose-cant-create-a-custom-role-and-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!