4.8 KiB
4.8 KiB
MOTM Application - Container Deployment
This document provides instructions for deploying the MOTM (Man of the Match) application using Docker containers.
Quick Start
Using Docker Compose (Recommended)
-
Clone the repository and navigate to the project directory
cd motm_app -
Start the application with PostgreSQL
docker-compose up -d -
Access the application
- Main page: http://localhost:5000
- Admin dashboard: http://localhost:5000/admin (username:
admin, password:letmein)
Using Docker Build
-
Build the container
docker build -f Containerfile -t motm-app . -
Run with external PostgreSQL
docker run -d \ --name motm-app \ -p 5000:5000 \ -e DATABASE_TYPE=postgresql \ -e DB_HOST=your-postgres-host \ -e DB_PORT=5432 \ -e DB_NAME=motm_db \ -e DB_USER=motm_user \ -e DB_PASSWORD=motm_password \ motm-app
Configuration
Environment Variables
| Variable | Default | Description |
|---|---|---|
DATABASE_TYPE |
postgresql |
Database type (postgresql/sqlite) |
DB_HOST |
postgres |
Database host (use postgres for docker-compose) |
DB_PORT |
5432 |
Database port |
DB_NAME |
motm_db |
Database name |
DB_USER |
motm_user |
Database username |
DB_PASSWORD |
motm_password |
Database password |
FLASK_ENV |
production |
Flask environment |
FLASK_RUN_HOST |
0.0.0.0 |
Flask host |
FLASK_RUN_PORT |
5000 |
Flask port |
SECRET_KEY |
your-secret-key-change-this-in-production |
Flask secret key |
Production Security
Important: Before deploying to production, change the following:
- Database credentials in
docker-compose.yml - Secret key in environment variables
- Admin password (use the admin profile page after first login)
Container Features
Multi-stage Build
- Builder stage: Installs dependencies and builds Python packages
- Runtime stage: Minimal image with only runtime dependencies
Security
- Runs as non-root user (
appuser) - Minimal attack surface with slim base image
- Health checks for container monitoring
Database Integration
- Automatic database connection waiting
- Database initialization support
- PostgreSQL optimized configuration
Monitoring
Health Checks
- Application health check:
curl -f http://localhost:5000/ - Database health check:
pg_isready
Logs
# View application logs
docker-compose logs motm-app
# View database logs
docker-compose logs postgres
# Follow logs in real-time
docker-compose logs -f motm-app
Maintenance
Backup Database
# Create backup
docker exec motm-postgres pg_dump -U motm_user motm_db > backup.sql
# Restore backup
docker exec -i motm-postgres psql -U motm_user motm_db < backup.sql
Update Application
# Pull latest changes
git pull
# Rebuild and restart
docker-compose down
docker-compose up -d --build
Reset Database
# Stop services
docker-compose down
# Remove database volume
docker volume rm motm_app_postgres_data
# Start fresh
docker-compose up -d
Troubleshooting
Common Issues
-
Database connection errors
- Check if PostgreSQL container is running:
docker-compose ps - Verify database credentials in environment variables
- Check database logs:
docker-compose logs postgres
- Check if PostgreSQL container is running:
-
Application won't start
- Check application logs:
docker-compose logs motm-app - Verify all environment variables are set correctly
- Ensure database is healthy before application starts
- Check application logs:
-
Port conflicts
- Change port mapping in
docker-compose.yml - Example:
"8080:5000"to use port 8080 instead of 5000
- Change port mapping in
Debug Mode
# Run container in interactive mode for debugging
docker run -it --rm \
-p 5000:5000 \
-e DATABASE_TYPE=postgresql \
-e DB_HOST=your-postgres-host \
-e DB_PORT=5432 \
-e DB_NAME=motm_db \
-e DB_USER=motm_user \
-e DB_PASSWORD=motm_password \
motm-app /bin/bash
File Structure
motm_app/
├── Containerfile # Docker container definition
├── docker-compose.yml # Multi-service orchestration
├── .dockerignore # Files to exclude from build
├── init.sql # Database initialization script
├── requirements.txt # Python dependencies
├── main.py # Main application file
├── static/ # Static assets (CSS, JS, images)
├── templates/ # HTML templates
└── data/ # Persistent data directory
Support
For issues or questions about container deployment, please check:
- Application logs:
docker-compose logs motm-app - Database logs:
docker-compose logs postgres - Container status:
docker-compose ps