DevContainer Setup
Complete guide to using VS Code DevContainers for isolated, consistent development environments.
What is DevContainer?
DevContainer provides a fully configured development environment inside a Docker container:
✅ Python 3.11 pre-installed
✅ All dependencies auto-installed via uv sync
✅ PostgreSQL and Redis services
✅ VS Code extensions pre-configured
✅ Consistent environment across team
Prerequisites
Required
- Docker Desktop - Must be running
- VS Code - Latest version
- Dev Containers Extension - Install from VS Code marketplace
Install Dev Containers Extension
- Open VS Code
- Press
Ctrl+Shift+X(Windows/Linux) orCmd+Shift+X(Mac) - Search for "Dev Containers"
- Install extension by Microsoft
Setup Instructions
1. Clone Repository
git clone https://github.com/equalcollective/santra-be.git
cd santra-be
2. Configure Environment
# Copy environment template
cp .env.example .env
Edit .env with required values:
SECRET_KEY=your-secret-key-here
AZURE_STORAGE_CONNECTION_STRING=your-connection-string
AZURE_STORAGE_CONTAINER_NAME=report-uploads
3. Open in Container
Option 1: Command Palette
- Open project in VS Code
- Press
F1orCtrl+Shift+P - Type: "Dev Containers: Reopen in Container"
- Select and wait for build (2-3 minutes first time)
Option 2: Notification
- VS Code will show notification: "Folder contains a Dev Container configuration file"
- Click "Reopen in Container"
Option 3: Status Bar
- Click the remote indicator in bottom-left corner (
><) - Select "Reopen in Container"
4. Wait for Build
First time setup:
- Pulls base images (~500MB)
- Installs system dependencies
- Runs
uv syncfor Python packages - Takes 2-3 minutes
Subsequent opens: < 30 seconds
5. Run Database Migrations
Once inside the container:
# Apply migrations
uv run alembic upgrade head
6. Start the API
# Start FastAPI with auto-reload
uv run uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
API available at: http://localhost:8000
What's Included
Services
All running automatically inside container network:
| Service | Host | Port | Purpose |
|---|---|---|---|
| app | localhost | 8000 | FastAPI application |
| db | db | 5432 | PostgreSQL 15 |
| redis | redis | 6379 | Cache & Celery |
VS Code Extensions
Pre-installed extensions:
- Python - Full Python language support
- Ruff - Fast Python linter and formatter
- Even Better TOML - TOML file support
Python Environment
- Python 3.11
uvpackage manager- Virtual environment at
/workspace/.venv - All dependencies from
pyproject.toml
Database Configuration
Environment variables automatically set:
DATABASE_URL=postgresql://orange_user:orange_password@db:5432/orange_db
REDIS_URL=redis://redis:6379/0
Working Inside Container
Terminal Access
Open integrated terminal (Ctrl+~`):
- Already inside the container
- Virtual environment activated
- All tools available (uv, alembic, pytest)
Running Commands
# Start API
uv run uvicorn app.main:app --reload
# Start Celery worker
uv run celery -A app.celery_app worker --loglevel=info
# Run migrations
uv run alembic upgrade head
# Create migration
uv run alembic revision --autogenerate -m "description"
Accessing Services
PostgreSQL:
# Via psql
psql postgresql://orange_user:orange_password@db:5432/orange_db
# Via Docker Compose
docker compose exec db psql -U orange_user -d orange_db
Redis:
# Test connection
redis-cli -h redis ping
File Editing
Edit files normally in VS Code:
- Files are mounted from host → container
- Changes sync instantly
- Git operations work on host files
Next Steps
- Development Commands - Common operations
- Docker Setup - Alternative setup method