Skip to content
docker-rocker logo

Docker Rocker

docker-rocker

Production-grade Docker containerization for FastAPI, Pytest, SQLModel, and Pydantic projects. This skill should be used when users ask to dockerize FastAPI applications, create multi-stage Docker builds, optimize Docker images for Python APIs, set up CI/CD Docker pipelines, or deploy containeriz...

SKILL.md

Full skill instructions

Docker Rocker

Production-grade Docker automation for Python FastAPI web API projects using multi-stage builds, UV package manager, and performance optimization strategies.

What This Skill Does

  • Creates optimized multi-stage Dockerfiles (Builder → Runtime → Testing stages)
  • Configures UV package manager for 50-70% faster dependency installation
  • Implements layer caching strategies for rapid rebuilds
  • Sets up non-root user security configurations
  • Generates docker-compose files for development and production
  • Optimizes for SQLModel/​Neon database connections in containers
  • Configures Pydantic settings for container environments

What This Skill Does NOT Do

  • Manage Kubernetes deployments (use dedicated k8s skills)
  • Handle cloud-specific container registries (AWS ECR, GCR, ACR)
  • Configure reverse proxies (Nginx, Traefik)
  • Manage container orchestration at scale
  • Handle secrets management beyond environment variables

Before Implementation

Gather context to ensure successful implementation:

SourceGather
CodebaseProject structure, existing Dockerfile, pyproject.toml/​requirements.txt, app entry point
ConversationTarget deployment (dev/​staging/​prod), database connection requirements, special dependencies
Skill ReferencesMulti-stage patterns from references/, optimization strategies, security practices
User GuidelinesTeam Docker conventions, registry requirements, CI/​CD integration needs

Ensure all required context is gathered before implementing. Only ask user for THEIR specific requirements (domain expertise is in this skill).


Required Clarifications

Ask about USER's context before generating Dockerfiles:

QuestionPurpose
Deployment target?Dev (hot-reload) vs Production (optimized) vs CI/​CD (testing)
Package manager?UV (recommended) vs pip vs Poetry
Database type?Neon PostgreSQL, local PostgreSQL, SQLite, other
Special system deps?Libraries requiring apt packages (Pillow, psycopg2, etc.)
Port configuration?Default 80 or custom port

Docker Deployment Stages

Stage Overview

StagePurposeBase ImageFinal Size
BuilderInstall dependencies, compile packagespython:3.12-slim~400MB (discarded)
RuntimeProduction applicationpython:3.12-slim~150MB
TestingCI/​CD test executionextends Builder~450MB
DevelopmentHot-reload for local devpython:3.12-slim~300MB

Stage Selection Logic

What is the deployment target?

Production deployment?
  → Use Builder + Runtime stages
  → Minimal image, no dev dependencies

CI/​CD pipeline?
  → Use Builder + Testing stage
  → Include pytest, dev dependencies

Local development?
  → Use Development stage
  → Volume mounts, hot-reload enabled

All of the above?
  → Generate complete multi-stage Dockerfile with all targets

Workflow

1. Analyze Project Structure

# Check for existing configurations
ls -la pyproject.toml uv.lock requirements*.txt Dockerfile docker-compose.yml

Identify:

  • Package manager (UV if uv.lock exists, Poetry if poetry.lock, pip otherwise)
  • Entry point (app/​main.py, src/​main.py, main.py)
  • Dependencies requiring system packages

2. Select Dockerfile Template

Based on user's deployment target, use appropriate template from assets/​templates/:

TargetTemplate
Production onlyDockerfile.production
With testingDockerfile.complete
DevelopmentDockerfile.dev
Full multi-stageDockerfile.multistage

3. Configure Environment Variables

# Performance optimizations
ENV UV_LINK_MODE=copy \
    UV_COMPILE_BYTECODE=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

# Application settings
ENV APP_MODULE=app.main:app \
    PORT=80

4. Optimize Layer Caching

Order Dockerfile instructions by change frequency:

  1. Base image (rarely changes)
  2. System dependencies (rarely changes)
  3. Python dependencies (changes occasionally)
  4. Application code (changes frequently)

5. Configure Database Connections

For Neon/​PostgreSQL in containers:

# Use NullPool - let external pooler handle connections
from sqlalchemy.pool import NullPool

engine = create_async_engine(
    DATABASE_URL,
    poolclass=NullPool,
    pool_pre_ping=True,
)

6. Generate docker-compose

Create appropriate compose file for target environment.

7. Validate Build

# Build and verify
docker build --target runtime -t app:latest .
docker run --rm app:latest python -c "import app; print('OK')"

Quick Commands

TaskCommand
Build production imagedocker build --target runtime -t app:prod .
Build test imagedocker build --target testing -t app:test .
Run tests in containerdocker run --rm app:test pytest -v
Build with no cachedocker build --no-cache -t app:latest .
Check image sizedocker images app:latest
Scan for vulnerabilitiesdocker scout cves app:latest

Error Handling

ErrorCauseSolution
uv: command not foundUV not installed in imageAdd COPY --from=ghcr.io/​astral-sh/​uv:latest /​uv /​bin/​uv
ModuleNotFoundErrorDependencies not in runtimeVerify COPY of .venv from builder
Permission deniedNon-root user can't writeUse --chown=app:app on COPY
Connection refused to DBNetwork isolationUse docker-compose networks or host.docker.internal
OOM killedContainer memory limitIncrease memory limit or optimize workers
Build cache not workingLayer order wrongReorder: deps before code

Output Checklist

Before delivering Dockerfile, verify:

  • Multi-stage build separates builder and runtime
  • UV cache mounts configured for fast rebuilds
  • UV_COMPILE_BYTECODE=1 set for startup speed
  • Non-root user created and used
  • .dockerignore includes .venv, pycache, .git
  • Layer order optimized (deps before code)
  • Health check configured
  • --proxy-headers flag for FastAPI behind load balancer
  • Database connection uses NullPool for external pooling
  • Secrets not hardcoded (use environment variables)

Reference Files

FileWhen to Read
references/​multi-stage-builds.mdUnderstanding stage architecture and patterns
references/​optimization-strategies.mdReducing image size and build time
references/​fastapi-patterns.mdFastAPI-specific Docker configurations
references/​security-best-practices.mdContainer security hardening
references/​database-connections.mdSQLModel/​Neon connection patterns in containers

Asset Templates

TemplateUse Case
assets/​templates/​Dockerfile.multistageComplete multi-stage (Builder + Runtime + Testing)
assets/​templates/​Dockerfile.productionProduction-only optimized build
assets/​templates/​Dockerfile.devDevelopment with hot-reload
assets/​templates/​docker-compose.ymlFull development stack
assets/​templates/​docker-compose.prod.ymlProduction compose
assets/​templates/​.dockerignoreStandard ignore patterns

More DevOps & CI/CD skills

Project scaffolding, deployment configuration, and CI/CD setup for Google ADK agents.

6K 472.6K
View

Set up tracing, logging, and monitoring for deployed ADK agents across Cloud Trace, BigQuery, and third-party platforms.

6K 472.6K
View

Enterprise Azure infrastructure architect generating Bicep or Terraform from workload descriptions.

1.5K 454.3K
View
azure-kubernetes logo
DevOps & CI/CD

azure-kubernetes

Plan and configure production-ready Azure Kubernetes Service clusters with Day-0 and Day-1 best practices.

1.5K 447.1K
View

Raw mechanical interfaces fusing Swiss typographic print with military terminal aesthetics. Rigid grids, extreme type scale contrast, utilitarian color, analog degradation effects. For data-heavy dashboards, portfolios, or editorial sites that need to feel like declassified blueprints.

92.7K 354.9K
View
just-scrape logo
DevOps & CI/CD

just-scrape

Web search, scraping, extraction, crawling, and monitoring via ScrapeGraph AI CLI.

69 245K
View

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

462 159.7K
View

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

462 159.1K
View
deploy-to-vercel logo
DevOps & CI/CD

deploy-to-vercel

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

31.9K 146.6K
View
programmatic-seo logo
DevOps & CI/CD

programmatic-seo

Build SEO-optimized pages at scale using templates, data, and proven playbook patterns.

53.3K 140.1K
View

Design and build isolated, reusable Convex backend components with clear boundaries and app-facing wrappers.

63 123.5K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
I
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View