'Cant connect to postgres db from pgadmin4

stackoverflow community!

i cant connect to postgres db from pgadmin

both of them run on separate containers

PGADMIN:

version: '3.8'

services:
  pgadmin:
    container_name: pgadmin4
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: 123
    volumes:
      - C:\Docker\pgadmin:/var/lib/pgadmin
    ports:
      - '8080:80'
    restart: unless-stopped
volumes:
  pgadmin:

POSTGRES:

version: '3.8'

services:
  postgres:
    container_name: postgres
    image: postgres
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: admin
      PGDATA: /var/lib/postgresql/data
    volumes:
      - C:\Docker\postgres14:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    restart: unless-stopped

volumes:
  postgres:

Pgadmin opens succcessfully from browser by address http://localhost:8080/browser/#

But in pgadmin i create server and type next data:

CREATE -> SERVER::

Name : mydatabase

**Connection**
hostname address : host.docker.internal
Port: 5432
maintance db : postgres
username: admin
password: admin

What i am doing here wrong ?



Solution 1:[1]

Because postgres is not in the pgadmin network, you can modify compose as

version: '3.8'

services:
  pgadmin:
    container_name: pgadmin4
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: 123
    volumes:
      - C:\Docker\pgadmin:/var/lib/pgadmin
    ports:
      - '8080:80'
    restart: unless-stopped
  postgres:
    container_name: postgres
    image: postgres
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: admin
      PGDATA: /var/lib/postgresql/data
    volumes:
      - C:\Docker\postgres14:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    restart: unless-stopped
volumes:
  pgadmin:
  postgres:

or you can find the network driver local ip:

docker network ls

shows network drivers, so find your driver then by:

docker network inspect network_name

find the local ip of driver.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MAM