A minimal Docker Compose setup for running PostgreSQL 16 and pgAdmin 4 locally.
git clone https://github.com/musay/postgres-pgadmin-docker
cd postgres-pgadmin-dockercp .env.example .envEdit .env with your preferred credentials:
POSTGRES_USER=devuser
POSTGRES_PASSWORD=devpass
POSTGRES_DB=devdb
PGADMIN_EMAIL=admin@local.dev
PGADMIN_PASSWORD=adminpassdocker-compose up -ddocker-compose down # stop (data persists)
docker-compose down -v # stop + wipe all data| Service | URL / Port | Default Credentials |
|---|---|---|
| PostgreSQL | localhost:5432 |
see .env |
| pgAdmin | http://localhost:5050 | see .env |
After opening http://localhost:5050, add a new server with:
| Field | Value |
|---|---|
| Host | postgres |
| Port | 5432 |
| Database | devdb |
| Username | devuser |
| Password | devpass |
⚠️ Usepostgresas the host — notlocalhost. Services communicate over the internal Docker network.
JDBC (Spring Boot)
spring.datasource.url=jdbc:postgresql://localhost:5432/devdb
spring.datasource.username=devuser
spring.datasource.password=devpasspsql CLI
docker exec -it postgres_dev psql -U devuser -d devdbData is stored in a named Docker volume (pgdata). It survives docker-compose down restarts.
To fully reset:
docker-compose down -v.
├── docker-compose.yml
├── .env # local credentials (not committed)
├── .env.example # template — safe to commit
├── .gitignore
└── README.md
Make sure your .gitignore includes:
.env
postgres-data/
Never commit .env — it contains credentials.