Learn how to login into postgres DB without password.

When postgres is pulled as docker image, we can create container as below.

$ docker run -d \
    --name some-postgres \
    -e POSTGRES_PASSWORD=mysecretpassword \

Note here we are supplying postgres password and if we try to omit POSTGRES_PASSWORD, then we will usually end up with error stating “no password supplied.” and fails to create container.

Once we create DB we can edit pg_hba.conf and make it work.

using find / locate commands find location of conf file and replace md5 with trust.

# To become root
$ sudo su -
# Using find command
$ find / -name pg_hba.conf

Also note with postgres container, neither vi nor yum commands will be available.

So hack is use cat command open conf file and edit in host OS and replace file.

$ mv pg_hba.conf pg_hba.conf.bkp
# Open conf file and edit in host OS
$ cat pg_hba.conf.bkp
$ cat > pg_hba.conf
# After replacing md5 to trust, paste file contents and save 

Leave a Reply

Your email address will not be published.

nineteen + eight =