Docker

From UitbreidenOS/UitKit · View interactive version

Docker is an AI agent skill from the GitHub repository UitbreidenOS/UitKit. Dockerfile best practices, multi-stage builds, Compose services, networking, volumes, build caching

How to use this skill

Skill file

Docker Skill

When to activate

When NOT to use

Instructions

Production Dockerfile structure

Always use multi-stage builds for compiled languages and Node.js:

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

# Stage 2: Runtime — minimal image
FROM node:20-alpine AS runtime
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY . .
USER appuser
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD wget -qO- http://localhost:8080/healthz || exit 1
CMD ["node", "server.js"]

Security rules

Layer caching optimization

Order Dockerfile instructions from least-to-most frequently changing:

  1. Base image (changes rarely)
  2. System dependencies (apt-get, apk add)
  3. Package manager files (package.json, requirements.txt)
  4. Package install (npm ci, pip install)
  5. Application code (COPY . .) — changes most often, must be last

.dockerignore — always include

node_modules/
.git/
.env
.env.*
*.md
Dockerfile*
docker-compose*
.dockerignore
coverage/
.nyc_output/
__pycache__/
*.pyc
.pytest_cache/

Docker Compose for local development

services:
  app:
    build:
      context: .
      target: builder          # Use build stage, not runtime stage locally
    volumes:
      - .:/app                 # Hot reload
      - /app/node_modules      # Don't overwrite container node_modules
    ports:
      - "8080:8080"
    environment:
      - NODE_ENV=development
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: dev_password   # Dev only — never production
      POSTGRES_DB: appdb
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app -d appdb"]
      interval: 5s
      timeout: 5s
      retries: 5
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data:

Common build failures

Example

User: Write a production Dockerfile for a Python FastAPI app with multi-stage build, non-root user, and health check.

Expected output:


Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.