0

I am having trouble connecting via pgAdmin to a postgresql database, which is in a docker compose container.

In docker compose I run 3 images, one an nginx server, another a laravel server and finally postgrest. But from outside of docker composer, I can't connect with pgAdmin, if the laravel server can connect with the db.

version: '3.8'
services:
    webserver:
        image: nginx:latest
        container_name: webserver
        restart: unless-stopped
        depends_on:
            - php
        ports:
            - "8001:80"
        volumes:
            - ./:/var/www
            - ./Dockerfiles/nginx:/etc/nginx/conf.d
        networks:
            app-network:
    php:
        build:
            context: Dockerfiles/php
            dockerfile: Dockerfile
        container_name: backend
        volumes:
            - ./:/var/www
            - ./Dockerfiles/php/php.ini:/usr/local/etc/php/conf.d/local.ini

        networks:
            app-network:
    database:
        image: postgres:latest
        container_name: postgres-db
        environment:
            POSTGRES_PASSWORD: postgres
            POSTGRES_USER: postgres
            POSTGRES_DB: pg-db
        ports:
            - "5435:5432"
        volumes:
            - postgres-data:/var/lib/postgresql/data
            # add entrypoint script to init db
            - ./Dockerfiles/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql
        networks:
            app-network:
networks:
    app-network:
volumes:
    app-data:
    postgres-data:

this is the pgAdmin server config:

enter image description here

But I get this pgAdmin output:

Unable to connect to server:

could not connect to server: connection refused. Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?

3
  • is pg admin running as a docker container ? Commented Nov 13, 2022 at 20:16
  • @DefSoudani not it is not running as docker container? it's necesary? Commented Nov 13, 2022 at 20:47
  • @JAOdev no, see my answer below Commented Nov 15, 2022 at 9:45

1 Answer 1

2

You might have a typo in you compose file:

 ports:
   - "5435:5432"

you are forwarding the postgres container 5432 port to your host 5435 port. So either change this to 5432:5432 or with pgadmin running on your host machine connect to the 5435 port.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.