0

I wanted to set up pgAdmin with Postgres with Docker Compose but im having some problems. After logging in to pgAdmin I get this warning when clicking the server, and entering "password123" just keep the message coming back.

The error i get: FATAL: password authentication failed for user "user".

My docker compose:

version: '2'

networks:
  appnetwork:
    driver: bridge

services:
  
  postgresql:
    image: 'bitnami/postgresql:latest'
    ports:
      - '5432'
    networks:
      - appnetwork
    environment:
      - POSTGRESQL_USERNAME=user
      - POSTGRESQL_PASSWORD=password123
      - POSTGRESQL_DATABASE=my_database
    volumes:
      - ./postgresdata:/bitnami/postgresql

  pgAdmin:
    image: 'dpage/pgadmin4'
    ports:
      - '8001:80'
    networks:
      - appnetwork
    environment:
      - PGADMIN_DEFAULT_EMAIL=admin@admin.com
      - PGADMIN_DEFAULT_PASSWORD=password123
    volumes:
      - ./configs/pgadmin_servers.json:/pgadmin4/servers.json
      - ./configs/pgpass:/var/lib/pgadmin/pgpass/pgpass

pgadmin_servers.json

{
    "Servers": {
      "1": {
        "Name": "docker_postgres",
        "Group": "Servers",
        "Host": "host.docker.internal",
        "Port": 5432,
        "MaintenanceDB": "postgres",
        "Username": "user",
        "PassFile": "/var/lib/pgadmin/pgpass/pgpass",
        "SSLMode": "prefer"
      }
    }
  }

pgpass:

host.docker.internal:5432:my_database:user:password123

If I use the CLI with Docker Desktop and cd to /var/lib/pgadmin/pgpass/ on the instance running pgadmin i can cat the file and its what I've set in my config folder.

1 Answers1

0

host.docker.internal is the hostname of the Docker host, not of the PostgreSQL container. In order to connect to the PostgreSQL container you need to use the name of its service as hostname, in this case postgresql.

This is how pgadmin_servers.json should look like:

{
  "Servers": {
    "1": {
      "Name": "docker_postgres",
      "Group": "Servers",
      "Host": "postgresql",
      "Port": 5432,
      "MaintenanceDB": "postgres",
      "Username": "user",
      "PassFile": "/var/lib/pgadmin/pgpass/pgpass",
      "SSLMode": "prefer"
    }
  }
}

Also, as PostgreSQL docs specify here, the pgpass file must have specific permissions in order to work, so it will be ignored unless you apply some changes to docker-compose.yml like those explained in the answers to this question.

Danysan
  • 128
  • 1
  • 8