This document provides instructions for setting up and running the Full-Stack Todo Application using Docker Compose for local development.
The Docker Compose configuration sets up a complete development environment with:
- Frontend: Next.js application running on port 3000
- Backend: FastAPI server running on port 8000
- Database: PostgreSQL server running on port 5432
- Cache: Redis server running on port 6379 (optional)
- Docker Desktop (Windows/Mac) or Docker Engine (Linux)
- Docker Compose v2+
- At least 4GB of free RAM recommended
git clone <repository-url>
cd From_Console_to_CloudCreate a .env file in the root directory:
# .env
SECRET_KEY=your_very_long_random_secret_key_for_development
NEXT_PUBLIC_API_URL=http://localhost:8000
NEXT_PUBLIC_BETTER_AUTH_URL=http://localhost:3000# Build and start all services in detached mode
docker compose up --build -d
# Or start without detached mode to see logs
docker compose up --build- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- Backend Documentation: http://localhost:8000/docs (if enabled in development)
- Port: 8000 (accessible from host)
- Container Port: 7860 (internal container port)
- Build Context:
./backend - Environment Variables:
DATABASE_URL: PostgreSQL connection stringSECRET_KEY: JWT secret keyENVIRONMENT: Set to "development"LOG_LEVEL: Set to "DEBUG" for development
- Port: 3000 (accessible from host)
- Build Context:
./full-stack-todo - Environment Variables:
NEXT_PUBLIC_API_URL: Backend API URLNEXT_PUBLIC_BETTER_AUTH_URL: Authentication URL
- Port: 5432 (accessible from host)
- Image: postgres:15
- Database:
todo_app - User:
postgres - Password:
postgres - Initialization: Runs
init.sqlon first startup
- Port: 6379 (accessible from host)
- Image: redis:7-alpine
- Purpose: Caching and session management
# Build all services
docker compose build
# Build specific service
docker compose build backend
docker compose build frontend# Start all services in detached mode
docker compose up -d
# Stop all services
docker compose down
# Stop specific service
docker compose stop backend
# Restart services
docker compose restart# View logs for all services
docker compose logs
# View logs for specific service
docker compose logs backend
docker compose logs frontend
docker compose logs db
# Follow logs in real-time
docker compose logs -f backend# Access backend container
docker compose exec backend bash
# Access frontend container
docker compose exec frontend sh
# Access database container
docker compose exec db psql -U postgres -d todo_app-
Initial Setup:
docker compose build docker compose up -d
-
During Development:
- The backend service is configured with
--reloadfor hot reloading - Code changes in
./backendare reflected in the container - Frontend changes require rebuilding the container
- The backend service is configured with
-
Database Operations:
# Run migrations (execute inside backend container) docker compose exec backend python -m alembic upgrade head # Connect to database docker compose exec db psql -U postgres -d todo_app
For active frontend development, you might prefer running the frontend locally:
-
Start only backend and database:
docker compose up -d backend db
-
Run frontend locally:
cd full-stack-todo pnpm install pnpm dev
Create a .env file in the project root:
# JWT Secret (at least 32 characters for production)
SECRET_KEY=very_long_random_string_for_development
# Frontend Configuration
NEXT_PUBLIC_API_URL=http://localhost:8000
NEXT_PUBLIC_BETTER_AUTH_URL=http://localhost:3000
# Database (only needed if overriding defaults)
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/todo_appYou can also create environment files for specific services:
./backend/.env- Backend-specific variables./full-stack-todo/.env- Frontend-specific variables
The database is initialized with the init.sql file on first startup. This file creates:
userstabletaskstable- Required indexes
- Sample data (optional)
If you modify init.sql, you'll need to recreate the database container:
# Remove database volume (WARNING: This deletes all data!)
docker compose down
docker volume rm from_console_to_cloud_postgres_data
docker compose up -dIf you get "port already in use" errors:
- Check if services are already running:
docker compose ps - Stop conflicting services or change ports in
docker-compose.yml
If dependencies fail to install:
- Clear Docker build cache:
docker builder prune - Rebuild with:
docker compose build --no-cache
If the backend can't connect to the database:
- Check that the database service is running:
docker compose ps - Verify the
DATABASE_URLenvironment variable - Check database logs:
docker compose logs db
# Check running services
docker compose ps
# Check resource usage
docker stats
# Clean up unused resources
docker system prune
# Remove all containers, networks, images, and volumes
docker compose down -v
docker system prune -aThis development configuration includes:
- Hot reloading capabilities
- Direct volume mounts for live code updates
- Less restrictive security settings
- Development-focused logging
For production deployment, consider:
- Using a production-ready reverse proxy (nginx)
- SSL termination
- Separate build and runtime images
- Proper secrets management
- Database backup strategies
- Monitoring and alerting
Modify the port mappings in docker-compose.yml:
services:
backend:
ports:
- "8001:7860" # Change host port from 8000 to 8001
frontend:
ports:
- "3001:3000" # Change host port from 3000 to 3001To add new services (like Elasticsearch, RabbitMQ, etc.), add them to docker-compose.yml:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.0
ports:
- "9200:9200"
environment:
- discovery.type=single-node
- xpack.security.enabled=falseDifferent configurations are available:
- Default (
docker compose up): Full development stack - Development (
docker compose -f docker-compose.dev.yml up): Development-specific configuration
To completely clean up Docker resources:
# Stop and remove containers, networks, and volumes
docker compose down -v
# Remove associated images (optional)
docker compose down --rmi all
# Clean up unused Docker resources
docker system pruneThis Docker Compose setup provides a complete local development environment that mirrors production as closely as possible while enabling rapid development and iteration.