1
votes

I'm trying to configure my docker to pgadmin4 in my nest js project, to do the backend, but when i try connect, show this message "Unable to connect to server:

could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting"

I already tried configure the docker-compose.yml with pgadmin configurations, network configurations and

my docker-compose.yml

version: '3'
services:
  db:
    image: postgres
    environment:
      POSTGRES_PASSWORD: "12345678"
    ports:
      - "5432:5432"
    volumes:
      - ./data/pgadmin/
    networks:
      - pg-network

  pgadmin:
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: "[email protected]"
      PGADMIN_DEFAULT_PASSWORD: "abc"
    ports:
      - "5050:80"
    depends_on:
      - db
    networks:
      - pg-network

networks: 
  pg-network:
    driver: bridge

My actual result is connection refused is server running on host "localhost (127.0.0.1) and accepting" but i expect he open the pgadmin to create the database

1
that config worked for me--and I just copy/pasted what you wrote. Where are you seeing the error? In the browser, in your terminal? And you got the postgres image from Docker Hub?richyen
i trying run the "yarn docker:up" and execute this command "docker-compose up -d", and yes, i got postgres image, i can connect with other servers, just dont work with my localhostLucas Buchalla Sesti
Are there any other error messages? The “connection refused” error usually means the database failed to start up. I wonder if removing the volumes section might fix it for yourichyen
was the name of host, the @Sivakumar save me, is not localhost to connect, and is a “db”Lucas Buchalla Sesti
Ah I see. Yeah screenshot helped!richyen

1 Answers

3
votes

Your docker-compose.yml is good. Please see the attached host name should be 'db'

enter image description here