agentleFS
komlukkomluk/scaffolding/skills/docker-templates/SKILL.md

docker-templates

Skill16 starsChanged 5 days agoMITView on GitHub

Docker multi-stage build templates, image security, and docker-compose patterns. TRIGGER when: writing a Dockerfile, composing services, or hardening a container image. SKIP: CI pipeline definitions (use github-actions-template); runtime monitoring (use monitoring-observability).

  • Reads credentials

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Always set memory limits. Log to stdout/stderr, never to files inside containers.

    line 131

≈ “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

Multi-stage Build Pattern

# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production=false
COPY . .
RUN npm run build

# Production stage
FROM node:20-alpine AS production
WORKDIR /app

# Security: Non-root user
RUN addgroup -g 1001 -S nodejs && \
    adduser -S nextjs -u 1001

# Copy only production artifacts
COPY --from=builder --chown=nextjs:nodejs /app/dist ./dist
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./

USER nextjs
EXPOSE 3000

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1

CMD ["node", "dist/server.js"]

Docker Security Best Practices

PracticeImplementation
Non-root userUSER nodejs after setup
Minimal base imageUse -alpine variants
No secrets in imageUse runtime env vars
Pin versionsFROM node:20.10.0-alpine
.dockerignoreExclude node_modules, .git, .env
Read-only filesystem--read-only flag when possible
Resource limitsSet memory/CPU limits

Docker Compose Patterns

version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
      target: production
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - DATABASE_URL=${DATABASE_URL}
    depends_on:
      db:
        condition: service_healthy
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost:3000/health"]
      interval: 30s
      timeout: 10s
      retries: 3

  db:
    image: postgres:15-alpine
    environment:
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=${DB_NAME}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER}"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  postgres_data:

Image Size Targets

App TypeTarget SizeStrategy
Python API< 200MBpython:3.12-slim + multi-stage
Node.js API< 150MBnode:20-alpine + multi-stage
Go binary< 50MBgolang:1.21-alpine build, scratch runtime

Health Check Configuration

SettingRecommended
Interval30s
Timeout10s
Retries3
Start period30s

Return 200 for healthy, 503 for unhealthy. Keep checks lightweight.

Environment Variable Hierarchy

  1. Runtime environment variables (highest priority)
  2. .env file
  3. docker-compose.yml defaults
  4. Dockerfile ENV defaults (lowest)

Provide .env.example with placeholders (committed). Never commit .env files with secrets.

Resource Limits

ResourceDevelopmentProduction
Memory512MBBased on app profiling
CPU0.5Based on app profiling

Always set memory limits. Log to stdout/stderr, never to files inside containers.

Bundled References

Usable templates in references/ based on actual project patterns:

FileDescription
references/Dockerfile.reactReact + nginx multi-stage build (node:22-alpine build, nginx:alpine prod)
references/Dockerfile.pythonFastAPI multi-stage build (python:3.11-slim, uvicorn)
references/docker-compose.example.ymlMinimal FastAPI + Postgres + Redis stack

Copy and adapt these templates for new services. All include health checks, non-root users, and alpine base images.

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.