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
access Docker container:
docker exec -it vteck-db bash
Connect with the client: 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 connect with psql - U postgres.
Any problem with my first step's command?
From postgres readme on Docker hub:
POSTGRES_USERThis optional environment variable is used in conjunction with
POSTGRES_PASSWORDto 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 ofpostgreswill be used.
In other words if you put something into the POSTGRES_USER environment variable, the startup script will honor that and create that user instead of the default one (postgres, that is).
Also, this and other POSTGRES_* variables are only used during the initial startup, when the database directory is empty. So if you restart the container with some other value, it won't make any difference (you'll see in logs something about "database seems ok, skipping initialization") unless you manually deleted the database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With