0
votes
  1. Create a postgres docker container with below command - docker run -v /home/ec2-user/Vteck-postgres-data:/var/lib/postgresql/data -d -e POSTGRES_USER=odoo POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --name vteck-db postgres
  2. access to docker container - docker exec -it vteck-db bash
  3. root@f1ba565db798:/# psql -U postgres psql: error: could not connect to server: FATAL: role "postgres" does not exist

but if I create docker container with - docker run --rm -d -e POSTGRES_PASSWORD=root --name postgres postgres, I can successfully access into psql with psql - U postgres.

Any problem on my step 1's command?

1

1 Answers

1
votes

From postgres readme on Docker hub:

POSTGRES_USER

This optional environment variable is used in conjunction with POSTGRES_PASSWORD to set a user and its password. This variable will create the specified user with superuser power and a database with the same name. If it is not specified, then the default user of postgres will be used.

In other words if you specify POSTGRES_USER environment variable, there will be no postgres user. Instead, it will create a user with the name from the environment variable (odoo in your case).