C
C#3mo ago
Esa

✅ How come my containerized postgres+pgadmin won't let me connect to db from pgadmin?

Hi there, I've made a small docker compose file that should start up a simple db with pgadmin. But I am unable to connect from pgadmin, here's the file:
version: '3.8'

networks:
db-network:
driver: bridge

services:
db:
image: postgres
restart: always
environment:
POSTGRES_DB: DevelopmentDB
POSTGRES_USER: DevelopmentUser
POSTGRES_PASSWORD: DevelopmentPassword
volumes:
- postgres-db:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- db-network

pgadmin:
image: dpage/pgadmin4:latest
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: DevelopmentPassword
volumes:
- pgadmin-data:/var/lib/pgadmin
depends_on:
- db
ports:
- "5050:80"
networks:
- db-network

volumes:
postgres-db:
pgadmin-data:
version: '3.8'

networks:
db-network:
driver: bridge

services:
db:
image: postgres
restart: always
environment:
POSTGRES_DB: DevelopmentDB
POSTGRES_USER: DevelopmentUser
POSTGRES_PASSWORD: DevelopmentPassword
volumes:
- postgres-db:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- db-network

pgadmin:
image: dpage/pgadmin4:latest
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: DevelopmentPassword
volumes:
- pgadmin-data:/var/lib/pgadmin
depends_on:
- db
ports:
- "5050:80"
networks:
- db-network

volumes:
postgres-db:
pgadmin-data:
So in pgadmin I try connecting like the atttached snippet. Any ideas where I go wrong?
No description
9 Replies
cap5lut
cap5lut3mo ago
localhost is wrong, the containers see each other via their container name as hostname, so in this case it should be db for the host address in pgadmin
Esa
EsaOP3mo ago
Oh thank you - this clearly is something I should understand. Is that because you see the listing db under services?
cap5lut
cap5lut3mo ago
yes, thats what i tried to explain with the middle part ;p
Esa
EsaOP3mo ago
Ah thats what you meant with container name, ok thanks 🙂
cap5lut
cap5lut3mo ago
Docker Documentation
Networking
Learn how networking works from the container's point of view
cap5lut
cap5lut3mo ago
i guess since u use docker compose this will be also of good information for ya: https://docs.docker.com/compose/how-tos/networking/
Docker Documentation
Networking
How Docker Compose sets up networking between containers
Esa
EsaOP3mo ago
Thanks, this is helpful 🙂
cap5lut
cap5lut3mo ago
if ur questions are answered please dont forget to $close the thread
MODiX
MODiX3mo ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?