PgAdmin Connection Error: "getaddrinfo ENOTFOUND postgresdb" (Docker Compose)

30 views Asked by At

I'm trying to connect PgAdmin to a PostgreSQL container running with Docker Compose, but I'm encountering a connection error. My docker-compose file and env below

version: '3.9'

services:

  app:
    container_name: golang_container
    environment:
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=${DB_NAME}
      - DATABASE_HOST=${DB_HOST}
      - DATABASE_PORT=${DB_PORT}
      - PORT=8080
    tty: true
    build: .
    ports:
      - 8000:8080
    restart: on-failure
    volumes:
      - .:/app
    depends_on:
      - postgresdb
    networks:
      - learning

  postgresdb:
    image: postgres:latest
    container_name: postgres_container
    environment:
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=${DB_NAME}
      - DATABASE_HOST=${DB_HOST}
    ports:
      - '1234:5432'
    volumes:
      - ./pg_data:/var/lib/postgresql/data
    networks:
      - learning

volumes:
  pg_data:

networks:
  learning:
    driver: bridge

DB_HOST=postgresdb
DB_DRIVER=postgres
DB_USER=user
DB_PASSWORD=Admin247
DB_NAME=rssagg
DB_PORT=5432

i inspected the learning network and it turns out that the golang and postgres containers are not running in it. this is what i get when i inspect it.

[
    {
        "Name": "learning",
        "Id": "6d5484aaa96a11c227ca0c0b0b66b6b4b0a2270f6397304cc2d181f11feadf54",
        "Created": "2024-03-12T17:17:21.671046946+01:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.25.0.0/16",
                    "Gateway": "172.25.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]
0

There are 0 answers