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:
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?
