This guide covers deploying the Shared Shopping List application in production using Docker containers.
- Docker Engine 20.10+
- Docker Compose 2.0+
- At least 2GB RAM available
- 10GB disk space for containers and data
-
Clone and prepare the environment:
git clone https://github.com/hechi/shoppimo.git cd shoppimo cp .env.example .env -
Configure environment variables: Edit
.envfile and update:POSTGRES_PASSWORD: Set a secure passwordVITE_API_URL: Your domain/IP for API accessVITE_WS_URL: Your domain/IP for WebSocket connections
-
Deploy the application:
./scripts/deploy.sh
-
Access the application:
- Frontend: http://localhost (or your configured domain)
- Backend API: http://localhost:8080/api
- Health Check: http://localhost/health
| Variable | Description | Default | Required |
|---|---|---|---|
POSTGRES_DB |
Database name | shopping_lists |
No |
POSTGRES_USER |
Database user | shopping_user |
No |
POSTGRES_PASSWORD |
Database password | shopping_pass |
Yes |
POSTGRES_PORT |
Database port | 5432 |
No |
FRONTEND_PORT |
Frontend port | 80 |
No |
BACKEND_PORT |
Backend port | 8080 |
No |
VITE_API_URL |
API base URL | http://localhost:8080 |
Yes |
VITE_WS_URL |
WebSocket URL | ws://localhost:8080 |
Yes |
For production deployment, update these variables in your .env file:
# Security
POSTGRES_PASSWORD=your_very_secure_password_here
# Domain configuration
VITE_API_URL=https://your-domain.com
VITE_WS_URL=wss://your-domain.com
# Optional: Custom ports
FRONTEND_PORT=443
BACKEND_PORT=8080The production deployment consists of three main services:
- Container:
shopping-list-frontend-prod - Port: 80 (configurable via
FRONTEND_PORT) - Features:
- Static file serving with optimized caching
- API proxy to backend service
- WebSocket upgrade handling
- Health check endpoint at
/health - Security headers and GZIP compression
- Container:
shopping-list-backend-prod - Port: 8080 (configurable via
BACKEND_PORT) - Features:
- REST API endpoints
- WebSocket real-time communication
- Database connection pooling
- Health check endpoint at
/api/health - JVM optimization for containers
- Container:
shopping-list-db-prod - Port: 5432 (configurable via
POSTGRES_PORT) - Features:
- Persistent data storage
- Automatic schema initialization
- Health checks and monitoring
- Optimized for container environments
Main deployment script with the following commands:
# Full deployment (default)
./scripts/deploy.sh deploy
# Stop all services
./scripts/deploy.sh stop
# View logs
./scripts/deploy.sh logs
# Check service status
./scripts/deploy.sh status
# Health check
./scripts/deploy.sh healthDatabase management script:
# Run migrations
./scripts/migrate.sh migrate
# Create backup
./scripts/migrate.sh backup
# Restore from backup
./scripts/migrate.sh restore backup_20241024_123456.sql
# Show database status
./scripts/migrate.sh status- Frontend:
GET /health→ Returns "healthy" - Backend:
GET /api/health→ Returns "OK" - Database: PostgreSQL
pg_isreadycheck
All services include built-in Docker health checks:
# Check all service health
docker-compose -f docker-compose.prod.yml ps
# View detailed health status
docker inspect shopping-list-frontend-prod | grep -A 10 HealthCreate regular database backups:
# Create backup with timestamp
./scripts/migrate.sh backup
# Backups are stored in ./backups/ directory
ls -la backups/-
Stop the application:
./scripts/deploy.sh stop
-
Restore from backup:
./scripts/migrate.sh restore backups/backup_20241024_123456.sql
-
Restart the application:
./scripts/deploy.sh deploy
- All services communicate through internal Docker network
- Only necessary ports are exposed to host
- Frontend acts as reverse proxy for API access
- Database credentials via environment variables
- No hardcoded passwords in configuration
- Regular security updates via base image updates
- Input validation and sanitization
- XSS protection headers
- Rate limiting (configure in Nginx if needed)
- Static file caching with long expiration
- GZIP compression for text assets
- Optimized Nginx configuration
- CDN-ready static asset serving
- HikariCP connection pooling
- JVM container optimizations
- Efficient WebSocket connection management
- Database query optimization with indexes
- Proper indexing on frequently queried columns
- Connection pooling configuration
- Regular maintenance and vacuuming
-
Services won't start:
# Check logs ./scripts/deploy.sh logs # Check individual service docker-compose -f docker-compose.prod.yml logs backend
-
Database connection issues:
# Check database health ./scripts/migrate.sh status # Verify environment variables docker-compose -f docker-compose.prod.yml exec backend env | grep DATABASE
-
Frontend not loading:
# Check Nginx configuration docker-compose -f docker-compose.prod.yml exec frontend nginx -t # Check API connectivity curl -f http://localhost:8080/api/health
# View all logs
./scripts/deploy.sh logs
# Follow specific service logs
docker-compose -f docker-compose.prod.yml logs -f frontend
docker-compose -f docker-compose.prod.yml logs -f backend
docker-compose -f docker-compose.prod.yml logs -f postgres# Check resource usage
docker stats
# Check service health
./scripts/deploy.sh health
# Database performance
./scripts/migrate.sh statusFor high-traffic scenarios, consider:
- Load Balancer: Add Nginx load balancer for multiple backend instances
- Database Clustering: PostgreSQL replication for read scaling
- Container Orchestration: Kubernetes deployment for auto-scaling
The application is ready for integration with:
- Prometheus: Metrics collection from health endpoints
- Grafana: Dashboard visualization
- ELK Stack: Centralized logging
- Alertmanager: Alert notifications
-
Pull latest changes:
git pull origin main
-
Rebuild and deploy:
./scripts/deploy.sh deploy
-
Verify deployment:
./scripts/deploy.sh health
# Create backup before maintenance
./scripts/migrate.sh backup
# Run any new migrations
./scripts/migrate.sh migrate
# Check database status
./scripts/migrate.sh statusFor issues and questions:
- Check the troubleshooting section above
- Review application logs
- Verify configuration settings
- Check Docker and system resources
Remember to always backup your data before making significant changes to the production environment.