Zero to Container: Syncing VS Code with Docker and uv
In modern AI development, consistency is everything. To build a robust AI Analyst agent, you need an environment that is isolated but accessible. By combining uv, Docker, and Bind Mounts, you can write code in your local VS Code while it executes instantly inside a high-performance container.
Prerequisites
- Docker Desktop
- VS Code
-
uvinstalled locally
Phase 0: Getting uv on Your Machine
Before we containerize everything, you need uv installed locally to initialize your projects.
macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows (PowerShell)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
Step 1: Initialize the Local Project
Create your project folder and use uv to seed the basic Python structure.
mkdir ai-analyst-project && cd ai-analyst-project
uv init
Note: Rename the default hello.py to main.py to follow standard naming conventions.
Step 2: Create the Dockerfile
This file defines your environment. We removed the --frozen flag to ensure uv can generate a lockfile during the first build.
FROM python:3.12-slim
# Install uv from the official binary
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Set performance and sync settings
ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
# Install dependencies first (better caching)
COPY pyproject.toml uv.lock* ./
RUN uv sync --no-install-project
# Copy project files
COPY . .
RUN uv sync
Step 3: Create docker-compose.yml
This handles the volume mapping and keeps the container running with tail -f /dev/null.
services:
agent:
build: .
container_name: ai_analyst_dev
volumes:
- .:/app
env_file:
- .env
environment:
- UV_LINK_MODE=copy
tty: true
stdin_open: true
command: tail -f /dev/null
Step 4: Configuration & Secrets
Create a .dockerignore file to prevent local junk from entering your container:
.venv
__pycache__
.git
Finally, create a .env file in your local folder to store your API keys:
GEMINI_API_KEY=your_secret_key_here
Step 5: Start the Engine
Run these commands to build and enter your new development world:
- 1. Build & Start:
docker-compose up -d --build - 2. Log In:
docker exec -it ai_analyst_dev bash
Step 6: Verify the Live Sync
Confirm that your local VS Code is successfully talking to the container:
- Open
main.pyin VS Code locally. - Change the code to:
print("Containerized Agent is Active!") - In the Docker terminal you just logged into, run:
uv run main.py
The changes appear instantly!
Community Discussion (0)
Leave a Comment
No approved comments yet. Be the first to start the conversation!