Create docker-compose.yml
yaml
version: '3.8'
services:
postgres:
image: postgres:15-alpine
container_name: postgres_db
restart: always
environment:
POSTGRES_USER: myuser
POSTGRES_PASSWORD: mypassword
POSTGRES_DB: mydb
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
pgadmin:
image: dpage/pgadmin4
container_name: pgadmin
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin@example.com
PGADMIN_DEFAULT_PASSWORD: admin
ports:
- "5050:80"
depends_on:
- postgres
volumes:
postgres_data:
Run
bash
docker-compose up -d
Access
- PostgreSQL:
localhost:5432
- pgAdmin:
http://localhost:5050
Connect in pgAdmin
- Open pgAdmin at
localhost:5050
- Add new server:
- Name:
Local Postgres
- Host:
postgres
(service name) - Port:
5432
- Username:
myuser
- Password:
mypassword
- Name:
Done! 🚀