-1

I'm trying to run pgadmin and postgres on docker. both services seems to work. However to able to connect to postgres through pgadmin. return password incorrect even after typing the password you see in the docker-compose file.

docker-compose

services:
  postgres:
    container_name: postgres
    image: postgres
    environment:
      POSTGRES_USER: danny329
      POSTGRES_PASSWORD: danny329
      PGDATA: /data/postgres
    volumes:
      - postgres:/data/postgres
    ports:
      - "5432:5432"
    networks:
      - postgres
    restart: unless-stopped

  pgadmin:
    container_name: pgadmin_container
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
      PGADMIN_CONFIG_SERVER_MODE: 'False'
    volumes:
      - pgadmin:/var/lib/pgadmin

    ports:
      - "5050:80"
    networks:
      - postgres
    restart: unless-stopped

networks:
  postgres:
    driver: bridge

volumes:
  postgres:
  pgadmin:

Error screenshot:

screenshot

Note: the password i used is 'danny329'

Daniel Paul
  • 495
  • 1
  • 6
  • 13
  • What is the database host name that you use on pgadmin? – gohm'c Dec 01 '21 at 07:50
  • Im running postegres as a service as well... so it was diffcult to find the hostname, but found a solution which mentioned to use host.docker.internal instead. If you know any other way to find the hostname, that would be helpful. – Daniel Paul Dec 01 '21 at 07:53
  • When you browse to pgadmin home page, there will be a dialog asking you the database host name. What do you put for this field? – gohm'c Dec 01 '21 at 07:59
  • I didn't receive a dialog as such, only to enter password. – Daniel Paul Dec 01 '21 at 08:18
  • [This](https://www.pgadmin.org/docs/pgadmin4/latest/server_dialog.html#server-dialog) is the (connection tab) dialog where you specify the database host name. – gohm'c Dec 01 '21 at 08:28

1 Answers1

1

Since both your postgres container and pgadmin container are running on the same Docker bridge network, you can connect them to each other using thier container name. For more info see Networking in Compose

In this case for the pgadmin you can set the hostname to be postgres:

enter image description here

Ervin Szilagyi
  • 14,274
  • 2
  • 25
  • 40