I connect can to my pgadmin with db1
but impossible to connect in with db2
. I got this error Unable to conect to server: ...
(see picture). I have seen some post but none of them resolve my problem.
version: "3.9"
services:
web:
build:
context: .
dockerfile: ./Dockerfile
entrypoint: /code/docker-entrypoint.sh
restart: unless-stopped
ports:
- "8000:8000"
depends_on:
- db1
- db2
volumes:
- .:/code
db1:
container_name: database1
image: postgres:14.4
restart: unless-stopped
ports:
- "5432:5432"
environment:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
db2:
container_name: database2
image: postgres:14.4
restart: unless-stopped
ports:
- "5433:5433"
environment:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4:6.20
restart: unless-stopped
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: admin
PGADMIN_CONFIG_SERVER_MODE: 'False'
volumes:
- ./pgadmin:/var/lib/pgadmin
ports:
- '8001:80'
depends_on:
- db1
- db2
- web
2
Answers
The issue with db2 is the port
change to
As PGAdmin is running within the docker network, all you need to do is change the port to
5432
in PGAdmin dashboard. As you (PGAdmin) are already in the same network (docker network) with DB2, docker can resolve the host (db2) and port directly, hence no need to use the port map:But if you want to expose the DB2 to outside of docker network, then you can change the port number in compose (but it is not needed for PGAdmin):