W
W
why72016-12-24 11:21:18
PostgreSQL
why7, 2016-12-24 11:21:18

Why is user and database not created for postgresql in docker container?

I want to deploy a development environment on docker containers.
One of the containers is postgresql, with the following configuration in docker-compose.yml

version: '2'
services:
  postgresql:
    image: postgres:9.6
    ports:
      - '5432:5432'
    volumes:
      - /home/username/pgdata:/var/lib/postgresql/data
    container_name: postgresql
    environment:
      POSTGRES_DB: testdb
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: password

Next, I launch containers, go into the container with postgresql and try to connect to the database
psql -h localhost -p 5432 -U admin -d testdb -W
. After entering the specified password in docker-compose.yml, I get the answer:
psql: FATAL: role "admin" does not exist
What am I doing wrong and where have I gone wrong?
PS Environment variables were forwarded to the container successfully
UPD: The problem is solved if you specify different volumes for each container with the base
. if there are two containers with a base, then volume can be specified as follows:
1st container:
volumes:
      - /home/username/pgdata/dbfirst:/var/lib/postgresql/data

2nd container:
volumes:
      - /home/username/pgdata/dbsecond:/var/lib/postgresql/data

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question