- Python 94.5%
- Dockerfile 5.5%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| init-scripts | ||
| webapp | ||
| docker-compose.yml | ||
| README.md | ||
DevOps Database Demo 🚀
A containerized full-stack application demonstrating Docker Compose, PostgreSQL, and Flask integration. This project showcases DevOps best practices including multi-container orchestration, database initialization, and health checks.
📋 Overview
This demo application provides a web interface for managing employees and projects, featuring:
- PostgreSQL Database: Persistent data storage with relational tables
- Flask Web App: Interactive UI for CRUD operations
- Docker Compose: Orchestrated multi-container deployment
- Database Initialization: Automatic schema creation with sample data
🏗️ Architecture
┌─────────────────┐ ┌──────────────────┐
│ │ │ │
│ Flask Web App │ ◄─────► │ PostgreSQL DB │
│ (Port 8080) │ │ (Port 5432) │
│ │ │ │
└─────────────────┘ └──────────────────┘
│ │
└────────────────────────────┘
demo_network (bridge)
🛠️ Prerequisites
- Docker (version 20.10 or higher)
- Docker Compose (version 2.0 or higher)
🚀 Quick Start
-
Clone the repository (or create the project structure):
mkdir devops-demo && cd devops-demo -
Start the application:
docker-compose up -d -
Access the web interface:
http://localhost:8080 -
View logs (optional):
docker-compose logs -f -
Stop the application:
docker-compose down
📁 Project Structure
.
├── docker-compose.yml # Multi-container orchestration
├── init-scripts/
│ └── 01-create-tables.sql # Database schema and seed data
└── webapp/
├── Dockerfile # Flask app container definition
├── app.py # Main Flask application
└── requirements.txt # Python dependencies
🗄️ Database Schema
Employees Table
id- Auto-incrementing primary keyname- Employee full nameemail- Unique email addressdepartment- Department assignmentsalary- Compensation amountcreated_at- Record creation timestamp
Projects Table
id- Auto-incrementing primary keyname- Project namedescription- Project detailsmanager_id- Foreign key to employees (manager)status- Active, completed, or on-holdbudget- Project budgetstart_date/end_date- Project timelinecreated_at- Record creation timestamp
🔌 Database Connection
Connection String:
postgresql://postgres:devops_password@postgres:5432/demo_db
Connect from host machine using tools like pgAdmin or psql:
psql -h localhost -p 5432 -U postgres -d demo_db
# Password: devops_password
🎯 Features
Web Interface
- Dashboard: Real-time statistics (employee count, project count, total budget)
- Employee Management: Add, view, and delete employees
- Project Management: Create projects with manager assignments
- Data Validation: Form validation and database constraints
Technical Features
- Health Checks: Ensures database is ready before app starts
- Data Persistence: PostgreSQL data survives container restarts
- Network Isolation: Custom bridge network for secure communication
- Automatic Initialization: SQL scripts run on first startup
🔧 Configuration
Environment Variables
PostgreSQL (docker-compose.yml):
POSTGRES_PASSWORD: Database superuser passwordPOSTGRES_DB: Default database namePOSTGRES_USER: Database username
Flask App (docker-compose.yml):
DATABASE_URL: PostgreSQL connection string
Port Mappings
8080:5000- Web application (host:container)5432:5432- PostgreSQL database (host:container)
📝 Common Commands
Docker Compose Operations
# Start services in background
docker-compose up -d
# View running containers
docker-compose ps
# View logs
docker-compose logs -f webapp
docker-compose logs -f postgres
# Restart services
docker-compose restart
# Stop and remove containers
docker-compose down
# Stop and remove containers + volumes (DELETES DATA)
docker-compose down -v
# Rebuild containers
docker-compose up -d --build
Database Operations
# Access PostgreSQL CLI
docker exec -it demo_postgres psql -U postgres -d demo_db
# Backup database
docker exec demo_postgres pg_dump -U postgres demo_db > backup.sql
# Restore database
docker exec -i demo_postgres psql -U postgres demo_db < backup.sql
🐛 Troubleshooting
Database connection fails
# Check if PostgreSQL is healthy
docker-compose ps
# View PostgreSQL logs
docker-compose logs postgres
# Restart services
docker-compose restart
Port already in use
# Check what's using the port
lsof -i :8080 # or :5432
# Modify ports in docker-compose.yml if needed
Reset everything
# Stop containers and remove volumes
docker-compose down -v
# Start fresh
docker-compose up -d
🔒 Security Notes
⚠️ This is a development demo only!
For production use, you should:
- Use strong, unique passwords (not
devops_password) - Store secrets in environment files or secret managers
- Use HTTPS/TLS for database connections
- Implement proper authentication and authorization
- Enable PostgreSQL SSL mode
- Use production WSGI server (e.g., Gunicorn) instead of Flask dev server
📚 Learning Resources
- Docker Documentation
- Docker Compose Documentation
- PostgreSQL Documentation
- Flask Documentation
- SQLAlchemy Documentation
🤝 Contributing
This is a demo project for learning purposes. Feel free to:
- Fork and experiment
- Add new features (authentication, API endpoints, etc.)
- Improve the UI
- Add tests
📄 License
This project is provided as-is for educational purposes.
Built with 🐳 Docker • 🐘 PostgreSQL • 🐍 Flask