agentleFS
walterlowwalterlow/claude-skills/dockerize/SKILL.md

dockerize

Skill2 starsChanged 10 months agoMITView on GitHub

Analyze repositories to detect tech stacks, dependencies, and services, then generate production-ready Dockerfiles and compose.yml configurations. This skill should be used when users ask to containerize a project, create Docker configs, or set up a development/production environment for their codebase.

  • Reads credentials
  • Deletes or force-pushes
  • Installs packages

3 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions3 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 3

    1. OneByJorah/offivo★ 24same name
    2. OneByJorah/VirtOffice★ 24same name
    3. Pradnyeshp/Claude-Skills★ 2same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository3 other files it gives its agents.

The file

Show its rules and text

We split this skill into the rules it gives an agent

20 rules. About 0 are common, 12 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use --no-install-recommends to skip suggested packages you don't need.

    line 109
  2. Distinctive:

    Default Docker containers run as root.

    line 113
  3. Distinctive:

    Check something meaningful (DB connectivity, not just "process exists")

    line 139
  4. Distinctive:

    Keep checks lightweight (they run frequently)

    line 140
  5. Distinctive:

    Don't ship debug tools, test suites, or dev dependencies to production.

    line 144
  6. Very specific:

    Check package.json scripts: start, dev, build, serve

    line 261
  7. Very specific:

    Look for main or module fields

    line 262
  8. Very specific:

    Check for main.py, app.py, run.py, manage.py

    line 266
  9. Very specific:

    Look at pyproject.toml [tool.poetry.scripts] or [project.scripts]

    line 267
  10. Distinctive:

    Check for ASGI/WSGI entry points (uvicorn, gunicorn configs)

    line 268
  11. Very specific:

    Look for main.go in root or cmd/ directory

    line 271
  12. Very specific:

    Check go.mod for module name

    line 272
  13. Very specific:

    Check Cargo.toml for [[bin]] targets

    line 275
  14. Distinctive:

    Follow these best practices when generating Dockerfiles:

    line 280
  15. Distinctive:

    When generating Docker configurations, provide:

    line 372
  16. Distinctive:

    Run full analysis workflow

    line 383
  17. Distinctive:

    Add Redis service with appropriate configuration

    line 389
  18. Distinctive:

    Update app service with depends_on if needed

    line 390
  19. Distinctive:

    Environment Variables: Never hardcode secrets. Use environment variables or Docker secrets

    line 400
  20. Distinctive:

    Health Checks: Add appropriate health check endpoints when detected

    line 402

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Dockerize Skill

This skill analyzes codebases to automatically generate Docker configurations for containerized deployment.

Critical Docker Best Practices (MUST FOLLOW)

1. NEVER Use latest Tag

WRONG:

FROM node:latest
FROM python:latest
FROM nginx:latest

RIGHT:

FROM node:20.11.1-alpine3.19
FROM python:3.12.2-slim-bookworm
FROM nginx:1.25.4-alpine3.19

latest is a moving target. What works today may break tomorrow when the base image updates. Production deployments have failed due to unexpected base image changes. Pin versions for reproducible builds.

2. Use Minimal Base Images

Bloated images = larger attack surface, slower pulls, higher storage costs.

Instead ofUseSize Reduction
ubuntu:22.04python:3.12-slim~90% smaller
node:20node:20-alpine~80% smaller
python:3.12python:3.12-slim~85% smaller

For production, consider distroless images where possible.

3. NEVER Put Secrets in Dockerfiles

CATASTROPHICALLY WRONG:

ENV AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
ENV AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/...
ARG NPM_TOKEN=abc123

Secrets baked into images are extractable by anyone with image access. They persist in layer history, registries, and CI logs.

CORRECT - Use BuildKit secret mounts for build-time secrets:

# Secret available during build but NOT persisted in layer
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci

CORRECT - Pass secrets at runtime:

docker run -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID myapp

CORRECT - Use secrets management:

  • Docker Swarm secrets
  • Kubernetes secrets
  • HashiCorp Vault, AWS Secrets Manager

4. Optimize Layer Caching

Order by change frequency (least → most). Wrong order means npm/pip install runs from scratch on every code change.

WRONG (cache invalidated on ANY file change):

COPY . .
RUN npm install

RIGHT (npm install cached unless package.json changes):

COPY package.json package-lock.json ./
RUN npm ci
COPY . .

This single change can cut build times from 8 minutes to under 1 minute.

5. Combine RUN Commands

Each instruction creates a layer. Cleanup in a later layer doesn't save space.

WRONG (4 layers, cleanup doesn't work):

RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y wget
RUN apt-get clean

RIGHT (1 layer, cleanup actually saves space):

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
      curl \
      wget \
    && rm -rf /var/lib/apt/lists/*

Use --no-install-recommends to skip suggested packages you don't need.

6. Run as Non-Root User

Default Docker containers run as root. Combined with a container escape vulnerability, this could compromise your host.

WRONG:

CMD ["node", "server.js"]  # Runs as root

RIGHT:

RUN addgroup -S appgroup && adduser -S appuser -G appgroup
COPY --chown=appuser:appgroup . .
USER appuser
CMD ["node", "server.js"]

7. Always Include Health Checks

Without health checks, your orchestrator has no idea if your app is actually working vs stuck in a crash loop.

HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
  CMD curl -f http://localhost:3000/health || exit 1

Key points:

  • --start-period gives your app time to initialize
  • Check something meaningful (DB connectivity, not just "process exists")
  • Keep checks lightweight (they run frequently)

8. Use Multi-Stage for Dev vs Prod

Don't ship debug tools, test suites, or dev dependencies to production.

# Base stage
FROM node:20.11-alpine AS base
WORKDIR /app
COPY package*.json ./

# Development stage (with dev tools)
FROM base AS development
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]

# Builder stage
FROM base AS builder
RUN npm ci --only=production
COPY . .
RUN npm run build

# Production stage (minimal)
FROM node:20.11-alpine AS production
WORKDIR /app
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
COPY --from=builder --chown=appuser:appgroup /app/dist ./dist
COPY --from=builder --chown=appuser:appgroup /app/node_modules ./node_modules
USER appuser
EXPOSE 3000
CMD ["node", "dist/index.js"]

Build with target: docker build --target production -t myapp:prod .

9. Scan Images Regularly

That base image from last year has known CVEs. Update deliberately, not never.

# Docker Scout
docker scout cves myapp:latest

# Trivy
trivy image myapp:latest

Set up automated scanning in CI. Block deployments on critical vulnerabilities. Update base images monthly/quarterly with intentional testing.

10. Always Use .dockerignore

Without it, you're uploading your entire directory (including .git, node_modules, .env files) to the Docker daemon.

.git
node_modules
npm-debug.log
.env
.env.*
coverage
.nyc_output
*.md
.vscode
.idea
tests
__tests__

Be aggressive. If it's not needed in the final image, exclude it.


When to Use

  • User asks to "dockerize" a project or repository
  • User needs a Dockerfile or compose.yml
  • User wants to containerize their application
  • User asks how to run their project in Docker
  • User needs to set up a development environment image with Docker
  • User needs to set up a product environment image with Docker

Analysis Workflow

Step 1: Analyze Repository Structure

To understand the project, examine these files and patterns:

Package/Dependency Files:

  • package.json, package-lock.json, yarn.lock, pnpm-lock.yaml (Node.js)
  • requirements.txt, pyproject.toml, setup.py, Pipfile, poetry.lock (Python)
  • go.mod, go.sum (Go)
  • Cargo.toml, Cargo.lock (Rust)
  • pom.xml, build.gradle, build.gradle.kts (Java/Kotlin)
  • Gemfile, Gemfile.lock (Ruby)
  • composer.json (PHP)
  • *.csproj, *.fsproj, *.sln (C#/.NET)

Framework Detection Patterns:

  • Next.js: next.config.js, .next/ directory, next in dependencies
  • React: react in dependencies, src/App.jsx or src/App.tsx
  • Vue: vue.config.js, vue in dependencies
  • Express: express in dependencies
  • FastAPI: fastapi in requirements, uvicorn usage
  • Django: django in requirements, manage.py, settings.py
  • Flask: flask in requirements
  • Spring Boot: spring-boot in pom.xml/build.gradle
  • Rails: Gemfile with rails, config/routes.rb

Database/Service Detection:

  • PostgreSQL: psycopg2, pg, postgres in dependencies or connection strings
  • MySQL: mysql2, pymysql, mysql-connector in dependencies
  • MongoDB: mongoose, pymongo, mongodb in dependencies
  • Redis: redis, ioredis in dependencies
  • Elasticsearch: elasticsearch, @elastic/elasticsearch in dependencies
  • RabbitMQ: amqplib, pika in dependencies
  • Kafka: kafka-python, kafkajs in dependencies

Step 2: Determine Entry Points and Build Commands

Node.js Projects:

  • Check package.json scripts: start, dev, build, serve
  • Look for main or module fields
  • Identify if it's a monorepo (workspaces, lerna, nx, turborepo)

Python Projects:

  • Check for main.py, app.py, run.py, manage.py
  • Look at pyproject.toml [tool.poetry.scripts] or [project.scripts]
  • Check for ASGI/WSGI entry points (uvicorn, gunicorn configs)

Go Projects:

  • Look for main.go in root or cmd/ directory
  • Check go.mod for module name

Rust Projects:

  • Check Cargo.toml for [[bin]] targets
  • Look for src/main.rs

Step 3: Generate Dockerfile

Follow these best practices when generating Dockerfiles:

  1. Use multi-stage builds to minimize image size
  2. Pin base image versions (e.g., node:20-alpine not node:latest)
  3. Copy dependency files first to leverage layer caching
  4. Use non-root users for security
  5. Set appropriate WORKDIR
  6. Include health checks where applicable
  7. Use .dockerignore to exclude unnecessary files

Reference references/dockerfile-templates.md for language-specific templates.

BuildKit Best Practices

Leverage BuildKit features for faster builds and better security:

  1. Add syntax directive as the first line of every Dockerfile:
    # syntax=docker/dockerfile:1
  2. Use cache mounts to speed up repeated builds:
    • npm/yarn: RUN --mount=type=cache,target=/root/.npm npm ci
    • pip: RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
    • go mod: RUN --mount=type=cache,target=/go/pkg/mod go mod download
    • cargo: RUN --mount=type=cache,target=/usr/local/cargo/registry cargo build --release
  3. Use secret mounts for private dependencies (avoids secrets in image layers):
    RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci
  4. BuildKit is enabled by default in Docker Engine v23.0+ and Docker Desktop

Step 4: Generate compose.yml

Include detected services with sensible defaults:

services:
  app:
    build: .
    ports:
      - "3000:3000"  # Adjust based on detected port
    environment:
      - NODE_ENV=development
    depends_on:
      - db  # If database detected
    volumes:
      - .:/app  # For development hot-reload
      - /app/node_modules  # Prevent overwriting

  # Add detected services below

Service Configuration Defaults:

ServiceImageDefault PortVolume
PostgreSQLpostgres:16-alpine5432postgres_data:/var/lib/postgresql/data
MySQLmysql:83306mysql_data:/var/lib/mysql
MongoDBmongo:727017mongo_data:/data/db
Redisredis:7-alpine6379redis_data:/data
Elasticsearchelasticsearch:8.11.09200es_data:/usr/share/elasticsearch/data

Step 5: Generate Supporting Files

Always create .dockerignore:

node_modules/
__pycache__/
*.pyc
.git/
.env
.env.*
*.log
.DS_Store
Thumbs.db
dist/
build/
coverage/
.pytest_cache/
.mypy_cache/
target/

For development, optionally create:

  • compose.yml for dev-specific settings
  • compose.prod.yml for production configuration

Output Format

When generating Docker configurations, provide:

  1. Analysis Summary: Brief overview of detected tech stack
  2. Dockerfile: With inline comments explaining key decisions
  3. compose.yml: Ready to run with docker compose up
  4. .dockerignore: Appropriate exclusions for the tech stack
  5. Usage Instructions: Commands to build and run

Example Usage Patterns

User says: "Dockerize this project"

  • Run full analysis workflow
  • Generate all configuration files
  • Provide build/run instructions

User says: "Add Redis to my compose file"

  • Read existing compose.yml
  • Add Redis service with appropriate configuration
  • Update app service with depends_on if needed

User says: "Optimize my Dockerfile"

  • Read existing Dockerfile
  • Suggest multi-stage build improvements
  • Reduce image size
  • Improve layer caching

Important Considerations

  • Environment Variables: Never hardcode secrets. Use environment variables or Docker secrets
  • Ports: Detect actual ports from code (look for .listen(), PORT env var usage)
  • Health Checks: Add appropriate health check endpoints when detected
  • Development vs Production: Generate configs suitable for development by default, with notes on production hardening

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.