postgresqldockerpgadmin

Right parameters on pgadmin to connect to a postgresql docker instance


I'm trying to connect pgAdmin to an instance of PostgreSQL inside a Docker container. But I am confused because I could not find any combination that works.

This is my Docker compose file:

services:
  database:
    container_name: myapp-db
    image: postgres:17-alpine
    env_file: .env
    ports:
      - ${POSTGRES_PORT}:${POSTGRES_PORT}
    environment:
      POSTGRES_DB: myapp
      POSTGRES_HOST_AUTH_METHOD: trust
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
      interval: 10s
      timeout: 5s
      retries: 5
  pgadmin:
    container_name: myapp-pgadmin
    image: dpage/pgadmin4
    depends_on:
       database:
        condition: service_healthy
    ports:
      - "5050:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: ${POSTGRES_USER}
      PGADMIN_DEFAULT_PASSWORD: ${POSTGRES_PASSWORD}
    restart: unless-stopped
  backend:
    container_name:  myapp_api
    build: .
    ports:
      - 8080:8080
      - 9229:9229  # debugger port
    volumes:
      - .:/usr/src/app
      - /usr/src/app/.pnpm-store
      - /usr/src/app/node_modules
    command: pnpm start:docker
    depends_on:
       database:
        condition: service_healthy
    environment:
      PORT: 8080
      DATABASE_URL: postgres://postgres@postgres/myapp-db 

My .env file

POSTGRES_PORT="5432"
POSTGRES_USER="admin@company.com"
POSTGRES_PASSWORD="root"
POSTGRES_DB="myapp-db"

And my pgAdmin window is the one in which I confused:

enter image description here

I am using "root" as the password.

What am I doing wrong? I could not find the issue

Note: I have used several combinations; that screenshot is just one of the many. I cannot find the correct parameters, and the error is, because of security, very obscure as you can see:

enter image description here


Solution

  • The field Host name/address should just hold a domain name or IP which pgAdmin can resolve, then it will attempt to open a port there and start establishing a connection.

    In this case, either the docker compose service name database or the container name myapp-db should be usable as the host name.