sameersbn / docker-postgresql

Dockerfile to build a PostgreSQL container image which can be linked to other containers.
MIT License
1.05k stars 468 forks source link

psql: FATAL: password authentication failed for user "postgres" #112

Open StephanMeijer opened 6 years ago

StephanMeijer commented 6 years ago
$ sudo docker run --name postgresql -itd --restart always   --env 'PG_PASSWORD=postgres'   --env 'PG_TRUST_LOCALNET=true'   --publish 5432:5432   --volume /srv/docker/postgresql:/var/lib/postgresql   sameersbn/postgresql:9.6-2
59edeb353dec8c503a7f8d86396decfcdb31b98a3b463c3e9c990083fb4dc59e
$ psql -Upostgres -hlocalhost
Password for user postgres: 
psql: FATAL:  password authentication failed for user "postgres"
loaialsharee commented 1 month ago

If none of the above helped and you were sure that the port is free, you might consider removing all of your volumes, and turn on your containers again. I faced the same issue and removing the volumes brought me back on track!

  1. docker-compose down -v, where -v will remove all of your volumes
  2. docker-compose up --build
RobQuistNL commented 6 days ago

Also make sure you use the correct format;

services:
  postgresql:
    image: postgres:14-alpine
    volumes:
      - postgresql-storage:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=devpassword
      - POSTGRES_USER=devuser
      - POSTGRES_DB=devdb
      - POSTGRES_HOST_AUTH_METHOD=trust
postgresql://devuser:devpassword@postgresql:5432/devdb