

Problem
By default when we create docker in Postgres, we usually use this command to create a container
$ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
after that, we execute to Postgres container
for my case, I run created command
$ created hellodb
And we got an error
createdb: error: connection to server on socket “/var/run/postgresql/.s.PGSQL.5432” failed: FATAL: role “root” does not exist
Solution
By default shell use root to execute the command but when we create a Postgres container we assign a user named “postgres”
By this command
$ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
So we have to change the user in the shell to user postgres user by this command
$ su - posgres
You will see a user of the shell has been changed. Then you can use createdb command and enter to hellodb normally

Thank for reading & enjoy coding