Docker Compose configuration for orchestrating the full-stack Todo application with frontend, backend, and database services. This setup provides a complete development and deployment environment with a single command.
This DevOps repository contains the Docker Compose configuration that brings together all components of the Todo application:
- Frontend: React application served on port 3001
- Backend: FastAPI REST API on port 8000
- Database: PostgreSQL 13 for data persistence
- Docker 20.10+
- Docker Compose 2.0+
# Navigate to devops directory
cd devops
# Start all services in detached mode
docker-compose up -d --build
# View logs
docker-compose logs -f
# View specific service logs
docker-compose logs -f frontend
docker-compose logs -f backend
docker-compose logs -f db# Stop services
docker-compose down
# Stop and remove volumes (clears database)
docker-compose down -v- Image: Node 18 Alpine
- Port: 3001:3000
- Environment:
REACT_APP_API_URL=http://127.0.0.1:8000
- Features: Hot reload enabled, stdin_open for interactive mode
- Dependencies: Backend service
- Image: Python 3.9 Slim
- Port: 8000:8000
- Environment: Loaded from
../backend/.env - Features: Auto-reload, CORS enabled, API documentation
- Dependencies: Database service
- Image: PostgreSQL 13 Alpine
- Port: 5432:5432 (exposed for debugging)
- Environment:
POSTGRES_USER=userPOSTGRES_PASSWORD=shanPOSTGRES_DB=todo_list
- Volumes: Persistent data storage with named volume
All services run on the default Docker network with automatic DNS resolution:
- Frontend β Backend:
http://backend:8000 - Backend β Database:
postgresql://user:shan@db:5432/todo_list
devops/
βββ docker-compose.yml # Multi-service orchestration
βββ README.md # This file
Required adjacent directories:
βββ ../frontend/ # React application
β βββ Dockerfile
β βββ package.json
βββ ../backend/ # FastAPI application
βββ Dockerfile
βββ requirements.txt
βββ .env
POSTGRES_USER=user
POSTGRES_PASSWORD=shan
POSTGRES_DB=todo_list
DB_HOST=db
DB_PORT=5432environment:
- REACT_APP_API_URL=http://127.0.0.1:8000| Service | Internal Port | External Port | URL |
|---|---|---|---|
| Frontend | 3000 | 3001 | http://localhost:3001 |
| Backend | 8000 | 8000 | http://localhost:8000 |
| Database | 5432 | 5432 | postgresql://localhost:5432 |
# Test backend API
curl http://localhost:8000/health
# Test frontend
curl http://localhost:3001
# Test database connection
docker-compose exec db psql -U user -d todo_list -c "SELECT * FROM todos;"# Restart specific service
docker-compose restart backend
# Rebuild specific service
docker-compose up -d --build frontend
# View service status
docker-compose ps
# Execute commands in containers
docker-compose exec backend python -c "from app.database import create_tables; create_tables()"
docker-compose exec db psql -U user -d todo_list# Follow all logs
docker-compose logs -f
# Follow specific service
docker-compose logs -f backend
# View last 100 lines
docker-compose logs --tail=100
# View logs with timestamps
docker-compose logs -f -t# Clone repositories
git clone <frontend-repo>
git clone <backend-repo>
git clone <devops-repo>
# Ensure directory structure
project/
βββ frontend/
βββ backend/
βββ devops/
# Start services
cd devops
docker-compose up -d --build# Changes are hot-reloaded automatically
# No restart needed for code changes
# Rebuild if dependencies change
docker-compose up -d --build frontend# Changes are auto-reloaded by uvicorn
# No restart needed for code changes
# Rebuild if requirements.txt changes
docker-compose up -d --build backend# Apply migrations
docker-compose exec backend python -c "from app.database import create_tables; create_tables()"
# Reset database
docker-compose down -v
docker-compose up -d- Environment Variables: Use secrets management (Docker Secrets, Vault)
- Database: Use managed PostgreSQL service (AWS RDS, Google Cloud SQL)
- Reverse Proxy: Add nginx for SSL/TLS termination
- Scaling: Use Docker Swarm or Kubernetes for orchestration
- Monitoring: Add Prometheus, Grafana, or ELK stack
- Backups: Implement automated database backups
# Add to docker-compose.yml for production
services:
nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./ssl:/etc/nginx/ssl
depends_on:
- frontend
- backend- Frontend: ~200MB RAM
- Backend: ~150MB RAM
- Database: ~100MB RAM
# Add to service configuration
services:
backend:
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M- Credentials: Never commit
.envfiles with real credentials - Network: Use internal networks for service communication
- Volumes: Set appropriate permissions on mounted volumes
- Images: Use official images and scan for vulnerabilities
- Updates: Keep base images and dependencies updated
- Test changes locally with
docker-compose up - Ensure all services start successfully
- Verify inter-service communication
- Update documentation for configuration changes
- Submit pull request with clear description
This project is open source and available under the MIT License.