Catalogue / docker
docker
MITSignedDockerfile best practices, security hardening, multi-stage builds, and image optimization--- name: docker description: Dockerfile best practices, security hardening, multi-stage builds, and image optimization metadata: version: "1.1.0" ---
Docker Code Review Rules
Security (Critical)
- Build-Time Variable Safety: Always sanitize build-time variables sourced from CI/CD or
--build-argto prevent injection attacks. Validate and escape externally-sourced values before using inARG,ENV, orLABELdirectives - Template Variable Safety: Avoid template variables such as
{{ }}and undeclared variables in Dockerfiles. Add linting step to scan for these patterns during review - Run as non-root user (
USERdirective) - Don't store secrets in image (use runtime injection)
- Don't use
--privilegedwithout justification - Scan images for vulnerabilities
- Set
readonlyroot filesystem where possible
Base Images (Essential)
- Pin base image to specific version (not
latest) - Use official images from trusted sources
- Prefer minimal images (
alpine,slim,distroless) - Regularly update base images for security patches
Build Optimization (Essential)
- Use multi-stage builds to reduce final image size
- Order instructions by change frequency (cache optimization)
- Combine
RUNcommands to reduce layers - Use
.dockerignoreto exclude unnecessary files, sensitive data, and build artifacts likenode_modules
Instructions (Essential)
- Use
COPYinstead ofADD(unless extracting archives) - Set
WORKDIRbeforeCOPY/RUN - Use explicit
EXPOSEfor documentation - Set meaningful
LABELmetadata
Instructions (Advanced)
- Explicitly set
SHELLif bash/sh features are needed - Set environment variables with
ENVfor configuration (not secrets) - Clean up package manager caches after install (e.g.,
apt-get clean) - Understand
ENTRYPOINTvsCMD: useENTRYPOINTfor main command,CMDfor default args - Document container usage with OCI labels (
org.opencontainers.image.*)
Health Checks
- Include
HEALTHCHECKinstruction - Health check should verify app is actually working
- Set appropriate interval and timeout
Example Good Dockerfile Pattern (Advanced)
# Build stage FROM node:20-alpine AS builder WORKDIR /app COPY package*.json ./ RUN npm ci --only=production # Runtime stage FROM node:20-alpine # Add OCI labels for documentation LABEL org.opencontainers.image.title="My App" LABEL org.opencontainers.image.description="Production web application" LABEL org.opencontainers.image.version="1.0.0" RUN addgroup -S appgroup && adduser -S appuser -G appgroup WORKDIR /app # Copy dependencies and app files COPY --from=builder /app/node_modules ./node_modules COPY . . # Set environment variables (not secrets) ENV NODE_ENV=production USER appuser EXPOSE 3000 HEALTHCHECK CMD wget -q --spider http://localhost:3000/health || exit 1 # Use ENTRYPOINT for main command, CMD for default args ENTRYPOINT ["node"] CMD ["server.js"]
| File | Size | SHA-256 |
|---|---|---|
| SKILL.md | 3.0 kB | 35095039ff89 |
| SKILVAULT_SOURCE.json | 1.1 kB | fe154cbfe818 |
| THIRD_PARTY_NOTICES.md | 1.1 kB | 77d5848de93a |
Published verbatim from the pinned commit. Nothing is rewritten.
| Version | Pinned commit | Signed | |
|---|---|---|---|
| 0.1.0 Current | f0b07716f481 | 29 Nov 2026 |
Locking a skill to one version needs Pro.