docker-development
SKILL.md
Docker Development
Production-grade patterns for building, testing, and deploying Docker container images.
When to Use
- Writing or reviewing Dockerfiles
- Configuring docker-compose.yml / compose.yml
- Setting up docker-bake.hcl for multi-platform builds
- Testing container images in CI/CD pipelines
- Optimizing .dockerignore and build context
Core Principles
- Minimal images -- Use Alpine/distroless, multi-stage builds
- Security first -- Non-root users, no secrets in layers
- Testable -- Images must be verifiable in CI
- Reproducible -- Pin versions, use checksums
Quick Reference
Multi-Stage Build
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
FROM node:20-alpine
RUN addgroup -g 1001 app && adduser -u 1001 -G app -D app
USER app
COPY /app/node_modules ./node_modules
COPY . .
CMD ["node", "server.js"]
Layer Optimization
# Good - single layer, cleanup included
RUN apt-get update && \
apt-get install -y --no-install-recommends curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
Docker Bake (Multi-Platform)
target "app" {
dockerfile = "Dockerfile"
platforms = ["linux/amd64", "linux/arm64"]
tags = ["myapp:latest"]
cache-from = ["type=gha"]
cache-to = ["type=gha,mode=max"]
}
CI Testing Gotchas
These patterns prevent common failures:
-
Bypass entrypoint for testing -- Use
--entrypointto run commands directly:docker run --rm --entrypoint php myimage -v -
Mock DNS for upstream servers -- nginx/haproxy configs fail without resolution:
docker run --rm --add-host backend:127.0.0.1 nginx-image nginx -t -
Compose validation with required vars -- Create
.envfrom.env.examplebeforedocker compose config. -
Secret scanning exclusions -- Exclude
.env.example, README, and docs from secret scanners.
See references/ci-testing.md for comprehensive CI testing patterns.
.dockerignore Best Practices
A well-configured .dockerignore reduces build context size, speeds up builds, and prevents secrets from leaking into images.
Key Patterns to Exclude
# Version control
.git
.gitignore
# Dependencies (rebuilt in container)
node_modules
vendor
# Build artifacts
dist
build
*.o
*.pyc
__pycache__
# IDE and editor files
.vscode
.idea
*.swp
# CI/CD and config
.github
.gitlab-ci.yml
docker-compose*.yml
Makefile
# Documentation
*.md
LICENSE
docs
# Secrets and environment
.env
.env.*
*.pem
*.key
credentials.json
Rules
- Always exclude
.git-- it can be 10x+ the source size and leaks history - Exclude dependency dirs (
node_modules,vendor) -- they get rebuilt viaRUN npm ci/RUN composer install - Exclude secrets (
.env,*.pem,*.key) -- even if a later stage drops them, they persist in layer history - Keep it in sync -- when adding new top-level dirs, check if
.dockerignoreneeds updating
Compose Essentials
- Use
depends_onwithcondition: service_healthyfor startup ordering - Set
start_periodin healthchecks for slow-starting services - Use
internal: truenetworks for database isolation - Use
profilesfor optional services (dev tools, debug tools)
References
references/ci-testing.md-- Comprehensive CI testing patterns for Docker images
Weekly Installs
2
Repository
netresearch/doc…nt-skillGitHub Stars
1
First Seen
2 days ago
Security Audits
Installed on
amp2
cline2
opencode2
cursor2
kimi-cli2
codex2