0
votes

I created a Postgres container with docker

sudo docker run -d \
    --name dev-postgres \
    -e POSTGRES_PASSWORD=test \
    -e POSTGRES_USER=test \
    -v ${HOME}/someplace/:/var/lib/postgresql/data \
    -p 666:5432 \
    postgres

I give the Postgres instance test as a username and password as specified in the doc.

The Postgres port (5432) inside the container is linked to my 666 port on the host.

Now I want to try this out using psql

psql --host=localhost --port=666 --username=test

I'm prompted to enter the password for user test and after entering test, I get

psql: error: FATAL:  password authentication failed for user "test"
1

1 Answers

0
votes

There are different problems that can cause this

  • The version of Postgres on the host and the container might not be the same

    If you have to change the docker version of Postgres used, make sure that the container with the new version is not crashing. Trying to change the version of Postgres while using the same directory for data might cause problem as the directory was initialized with the wrong version.

    You can use docker logs [container name] to debug if it crashes

  • There might be a problem with the volumes used by docker (something with cached value preventing the creation of a new user when env variable change) if you changed the env parameters.

    docker stop $(docker ps -qa) && docker system prune -af --volumes
  • If you have problem with some libraries that use Postgres, you might need to install some package to allow libraries to work with Postgres. Those two are the one Stack Overflow answers often reference.
    sudo apt install libpq-dev postgresql-client
  • Other problems seem to relate to problems with docker configuration.