Docker & Environment Setup Skill
This skill covers all aspects of Docker infrastructure, environment configuration, and local development setup for the SE104_VLEAGUE project.
Infrastructure Overview
The project uses Docker for:
- •PostgreSQL Database: Running PostgreSQL 15+ locally
- •Optional Full Stack: Running API + Web + Database together
Docker Compose Configurations
Database Only (Recommended for Development)
Location: infra/docker-compose.db.yml
version: '3.8'
services:
postgres:
image: postgres:15
container_name: vleague-postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: vleague
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
Usage:
# Start PostgreSQL docker compose -f infra/docker-compose.db.yml up -d # Stop PostgreSQL docker compose -f infra/docker-compose.db.yml down # View logs docker compose -f infra/docker-compose.db.yml logs -f # Remove everything including volumes (WARNING: deletes data) docker compose -f infra/docker-compose.db.yml down -v
Full Stack (Root docker-compose.yml)
Location: docker-compose.yml
Includes:
- •PostgreSQL
- •API (NestJS)
- •Web (React + Vite)
# Build and start all services docker compose up --build # Start in detached mode docker compose up -d # Stop all services docker compose down # View logs for specific service docker compose logs api docker compose logs web docker compose logs postgres
Environment Variables
API Environment (.env for apps/api)
Create or copy from example:
cp apps/api/.env.example apps/api/.env
Required variables:
# Database connection DATABASE_URL="postgresql://postgres:postgres@localhost:5432/vleague" # Server configuration PORT=8080 NODE_ENV=development
[!IMPORTANT] When running API in Docker, change
localhosttopostgres(the service name) in DATABASE_URL.
Docker version:
DATABASE_URL="postgresql://postgres:postgres@postgres:5432/vleague"
Web Environment (.env for apps/web)
Create or copy from example:
cp apps/web/.env.example apps/web/.env
Required variables:
# API base URL VITE_API_BASE_URL=http://localhost:8080
[!NOTE] All Vite environment variables must be prefixed with
VITE_to be accessible in the browser.
Local Development Setup
Quick Start (Fresh Clone)
[!TIP] See
docs/FRESH_CLONE_CHECKLIST.mdfor the complete setup guide.
- •
Prerequisites:
bash# Check Node.js version (>= 20) node --version # Enable corepack for pnpm corepack enable
- •
Install Dependencies:
bashpnpm install
- •
Start PostgreSQL:
bashdocker compose -f infra/docker-compose.db.yml up -d
- •
Setup Environment Files:
bashcp apps/api/.env.example apps/api/.env cp apps/web/.env.example apps/web/.env
- •
Setup Database:
bashcd apps/api pnpm dlx prisma migrate dev --name init pnpm run db:seed cd ../..
- •
Start Development Servers:
bashpnpm dev
This runs both API and Web in parallel:
- •API: http://localhost:8080
- •Web: http://localhost:5173
Ports Configuration
| Service | Port | URL |
|---|---|---|
| PostgreSQL | 5432 | postgresql://localhost:5432 |
| API | 8080 | http://localhost:8080 |
| Web | 5173 | http://localhost:5173 |
[!WARNING] Port Conflicts: Make sure these ports are available on your system before starting services.
Docker Best Practices
For Development
- •
Use Database-Only Docker:
- •Run only PostgreSQL in Docker
- •Run API and Web locally with hot-reload
- •Faster feedback loop for development
bashdocker compose -f infra/docker-compose.db.yml up -d pnpm dev
- •
Check Container Status:
bashdocker ps # List running containers docker compose ps # List project containers
- •
View Container Logs:
bashdocker compose logs postgres -f
- •
Access PostgreSQL CLI:
bashdocker exec -it vleague-postgres psql -U postgres -d vleague
For Production/Testing
- •
Use Full Stack Docker:
bashdocker compose up --build
- •
Environment Variables:
- •Use
.envfiles or environment-specific configs - •Never commit
.envfiles with secrets
- •Use
- •
Volume Management:
bash# List volumes docker volume ls # Inspect volume docker volume inspect <volume_name> # Remove unused volumes docker volume prune
Troubleshooting
PostgreSQL Connection Issues
Problem: Cannot connect to PostgreSQL
Solutions:
- •
Check if container is running:
bashdocker ps | grep postgres
- •
Check logs:
bashdocker compose -f infra/docker-compose.db.yml logs postgres
- •
Verify DATABASE_URL in
.env:envDATABASE_URL="postgresql://postgres:postgres@localhost:5432/vleague"
- •
Test connection:
bashcd apps/api pnpm dlx prisma db pull
Port Already in Use
Problem: Port 5432/8080/5173 already in use
Solutions:
- •
Find and kill the process:
bash# Windows PowerShell Get-Process -Id (Get-NetTCPConnection -LocalPort 5432).OwningProcess Stop-Process -Id <PID> # Or change port in docker-compose ports: - "5433:5432" # Use different host port
- •
Update DATABASE_URL to match new port
Docker Container Won't Start
Problem: Container exits immediately
Solutions:
- •
Check logs for errors:
bashdocker compose logs
- •
Remove and recreate:
bashdocker compose down -v docker compose up --build
- •
Check disk space:
bashdocker system df docker system prune # Clean up
Database Data Persists After down
This is expected behavior - Docker volumes persist data.
To completely reset:
docker compose -f infra/docker-compose.db.yml down -v docker compose -f infra/docker-compose.db.yml up -d cd apps/api pnpm dlx prisma migrate dev pnpm run db:seed
[!CAUTION] Data Loss: The
-vflag removes volumes and deletes all database data. Use with caution.
Environment-Specific Configurations
Development
# apps/api/.env DATABASE_URL="postgresql://postgres:postgres@localhost:5432/vleague" PORT=8080 NODE_ENV=development
Docker Compose
# apps/api/.env (when running in Docker) DATABASE_URL="postgresql://postgres:postgres@postgres:5432/vleague" PORT=8080 NODE_ENV=production
CI/CD (GitHub Actions)
# .github/workflows/ci.yml env: DATABASE_URL: postgresql://postgres:postgres@localhost:5432/vleague_test
Docker Compose Commands Reference
# Start services docker compose up # Foreground docker compose up -d # Background (detached) docker compose up --build # Rebuild images # Stop services docker compose stop # Stop without removing docker compose down # Stop and remove containers docker compose down -v # Stop and remove volumes (DELETE DATA) # View status and logs docker compose ps # List containers docker compose logs # All logs docker compose logs -f api # Follow API logs docker compose logs --tail=100 web # Last 100 lines # Execute commands in containers docker compose exec api sh # Shell in API container docker compose exec postgres psql -U postgres -d vleague # Restart services docker compose restart api # Restart specific service docker compose restart # Restart all # Build docker compose build # Build all services docker compose build --no-cache api # Rebuild without cache
Development Workflows
Workflow 1: Local Development (Recommended)
# 1. Start only PostgreSQL docker compose -f infra/docker-compose.db.yml up -d # 2. Run API and Web locally pnpm dev # Hot-reload enabled for both API and Web
Advantages:
- •✅ Fast hot-reload
- •✅ Easy debugging
- •✅ Direct access to code
Workflow 2: Full Docker
# Run everything in Docker docker compose up --build # Rebuild on code changes docker compose up --build
Advantages:
- •✅ Production-like environment
- •✅ Consistent across machines
Disadvantages:
- •❌ Slower feedback loop
- •❌ Need to rebuild on changes
Workflow 3: Hybrid
# PostgreSQL in Docker docker compose -f infra/docker-compose.db.yml up -d # API locally cd apps/api pnpm dev # Web in Docker or locally cd apps/web pnpm dev
Health Checks
Check PostgreSQL
# Via Docker docker compose exec postgres pg_isready -U postgres # Via psql docker exec -it vleague-postgres psql -U postgres -d vleague -c "SELECT 1;"
Check API
curl http://localhost:8080/health
Should return: {"status":"ok"}
Check Web
Open browser: http://localhost:5173
File Locations Reference
| Purpose | File Path |
|---|---|
| Database Docker Compose | infra/docker-compose.db.yml |
| Full Stack Docker Compose | docker-compose.yml |
| API Environment | apps/api/.env |
| API Environment Example | apps/api/.env.example |
| Web Environment | apps/web/.env |
| Web Environment Example | apps/web/.env.example |
| Fresh Clone Guide | docs/FRESH_CLONE_CHECKLIST.md |
| Local Dev Guide | docs/LOCAL_DEV.md |
Common Issues and Solutions
"Prisma Client Not Found"
Cause: Prisma Client not generated after schema changes
Solution:
cd apps/api pnpm dlx prisma generate
"Migration Failed"
Cause: Database state conflicts with migrations
Solution:
cd apps/api pnpm dlx prisma migrate reset # WARNING: Deletes all data pnpm run db:seed
".env File Not Loaded"
Cause: Missing or incorrectly named file
Solution:
- •Check file name is exactly
.env(not.env.txt) - •Check file location matches service root
- •Restart the development server
Docker Volume Permission Issues
Cause: Volume ownership conflicts (rare on Windows)
Solution:
docker compose down -v docker volume prune docker compose up -d