Complete Docker Compose application with PostgreSQL and pgAdmin, includes scripts for backup, restoration and management.
Note: This README has been cleaned of duplications. For detailed script documentation, see scripts/README.md.
# Copy environment variables
cp .env.example .env
# Update values if necessary (optional)
# nano .env# Option 1: With script
bash scripts/start.sh
# Option 2: With make
make start
# Option 3: With Docker Compose directly
docker-compose up -d-
PostgreSQL:
localhost:5432- User:
dbuser(configurable in.env) - Database:
app_db
- User:
-
pgAdmin: http://localhost:5050/pgadmin
- Email:
admin@example.com - Password: configurable in
.env
- Email:
.
βββ docker-compose.yml # Services configuration
βββ .env # Environment variables (DO NOT commit)
βββ .env.example # Variables template (COMMIT this)
βββ Makefile # Useful commands
βββ README.md # This file
β
βββ scripts/
βββ README.md # Scripts documentation
βββ start.sh # Start application
βββ stop.sh # Stop application
βββ backup.sh # Create backup
βββ restore.sh # Restore backup
βββ status.sh # View status and logs
βββ init.sql # Initial SQL
βββ backups/ # Backup directory
βββ backup_*.sql.gz
make help # View all commands
make start # Start
make stop # Stop
make restart # Restart
make status # View status
make logs # View logs in real time
make backup # Create backup
make restore F=backups/backup_*.sql.gz # Restore backup
make clean # Clean everythingbash scripts/start.sh
bash scripts/stop.sh
bash scripts/status.sh -f
bash scripts/backup.sh
bash scripts/restore.sh backups/backup_*.sql.gzdocker-compose up -d # Start
docker-compose down # Stop
docker-compose ps # View status
docker-compose logs -f # View logs- Image:
postgres:17.5-alpine - Container:
postgres - Port:
5432(configurable) - Volume:
postgres-data - Health Check: Enabled (pg_isready every 10s)
- Image:
dpage/pgadmin4:latest - Container:
pgadmin - Port:
5050(configurable) - Volume:
pgadmin-data - Network: Connected to
app-network
- Name:
app-network - Driver:
bridge - Allows communication between PostgreSQL and pgAdmin
make backup
# or
bash scripts/backup.shSelect the database and backup type interactively:
Available databases:
1) sales_db
2) users_db
3) analytics_db
Select database number (1-3): 2
Backup type:
1) Full backup (with data)
2) Schema only (without data)
Select backup type (1-2): 1
Generates a compressed file: backups/backup_users_db_full_YYYYMMDD_HHMMSS.sql.gz or backups/backup_users_db_schema_only_YYYYMMDD_HHMMSS.sql.gz
make restore F=backups/backup_users_db_full_20251103_120000.sql.gz
# or
bash scripts/restore.sh backups/backup_users_db_full_20251103_120000.sql.gzSelect the destination database interactively:
Available destination databases:
1) sales_db
2) analytics_db
3) Create new database
Select destination database number (1-3): 3
Enter new database name: restored_users
ls -lh scripts/backups/
# Show only full backups
ls -lh scripts/backups/*full*
# Show only schema only
ls -lh scripts/backups/*schema_only*# Database
DB_PORT=5432 # Internal port
DB_EXTERNAL_PORT=5432 # Port on your machine
DB_NAME=app_db # Database name
DB_USERNAME=dbuser # PostgreSQL user
DB_PASSWORD=secure_password_here # PostgreSQL password
TIMEZONE=UTC # Timezone
# pgAdmin
PGADMIN_EMAIL=admin@example.com # Email
PGADMIN_PASSWORD=pgadmin_password_here # Password
PGADMIN_PORT=5050 # Access portImportant:
- Change passwords in production
- DO NOT commit
.envto repository - Use
.env.exampleas reference
- β Change default passwords
- β Do NOT expose ports unnecessarily
- β Use private networks in production
- β Perform backups regularly
- β Keep images updated
- Use Docker/Kubernetes secrets
- Implement SSL/TLS
- Configure firewall
- Monitor logs regularly
- Automate backups
# See detailed logs
docker-compose logs
# Check container status
docker ps -a# Ports are already in use. Options:
# 1. Change ports in .env
# 2. Stop the process using the port
# 3. Wait for it to release
# See what processes use the ports
lsof -i :5432
lsof -i :5050# Check if it's running
docker exec postgres pg_isready -U dbuser
# Check credentials in .env
# Check volumes are correct
docker inspect postgres# Make sure PostgreSQL container is running
docker ps
# Check logs
docker-compose logs postgresSee scripts/README.md for detailed script documentation.
- Update
.env.exampleif you add new variables