Learn Dockerfile fundamentals and best practices for building production-ready container images
Provides Dockerfile syntax guidance and 2024-2025 best practices for building secure, optimized container images. Use when creating or reviewing Dockerfiles to ensure proper layer ordering, non-root users, and production-ready configurations.
/plugin marketplace add pluginagentmarketplace/custom-plugin-docker/plugin install pluginagentmarketplace-docker-container-assistant@pluginagentmarketplace/custom-plugin-dockerThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/Dockerfile.templatereferences/DOCKERFILE-BEST-PRACTICES.mdscripts/dockerfile-lint.shMaster Dockerfile fundamentals and 2024-2025 best practices for building secure, optimized container images.
Provide comprehensive guidance on Dockerfile syntax, instruction ordering, layer optimization, and security best practices.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| base_image | string | No | - | Base image to use |
| language | string | No | - | Programming language (node/python/go/java) |
| optimize | boolean | No | true | Apply optimization recommendations |
| Instruction | Purpose | Example |
|---|---|---|
| FROM | Base image | FROM node:20-alpine |
| WORKDIR | Set working directory | WORKDIR /app |
| COPY | Copy files | COPY package*.json ./ |
| RUN | Execute command | RUN npm ci |
| ENV | Set environment | ENV NODE_ENV=production |
| EXPOSE | Document port | EXPOSE 3000 |
| USER | Set user | USER appuser |
| CMD | Default command | CMD ["node", "app.js"] |
| ENTRYPOINT | Fixed command | ENTRYPOINT ["./start.sh"] |
| HEALTHCHECK | Health check | HEALTHCHECK CMD curl -f http://localhost/ |
# 1. Base image (most stable)
FROM node:20-alpine
# 2. System dependencies
RUN apk add --no-cache curl
# 3. Create user (security)
RUN addgroup -g 1001 app && adduser -u 1001 -G app -D app
# 4. Set working directory
WORKDIR /app
# 5. Copy dependency files (cache layer)
COPY package*.json ./
# 6. Install dependencies
RUN npm ci --only=production
# 7. Copy application code (most volatile)
COPY --chown=app:app . .
# 8. Switch to non-root user
USER app
# 9. Health check
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:3000/health || exit 1
# 10. Default command
CMD ["node", "server.js"]
# Always use specific version tags
FROM node:20.10-alpine # Good
# FROM node:latest # Bad
# Run as non-root user
USER nonroot
# Use multi-stage builds
FROM node:20 AS builder
# ... build steps ...
FROM node:20-alpine AS runtime
COPY --from=builder /app/dist ./
# Combine RUN commands
RUN apt-get update && \
apt-get install -y --no-install-recommends curl && \
rm -rf /var/lib/apt/lists/*
# Use .dockerignore
# node_modules, .git, *.md, etc.
# Leverage BuildKit cache mounts
RUN --mount=type=cache,target=/root/.npm npm ci
| Error | Cause | Solution |
|---|---|---|
COPY failed: file not found | File outside context | Check .dockerignore |
returned non-zero code: 127 | Command not found | Install package first |
permission denied | Running as non-root | Use COPY --chown |
# Lint Dockerfile
hadolint Dockerfile
# Build with no cache
docker build --no-cache -t app:test .
# Inspect layers
docker history app:test
| Symptom | Cause | Fix |
|---|---|---|
| Large image size | No multi-stage | Add build stage |
| Slow builds | Poor layer order | Move COPY after dependencies |
| Security warnings | Root user | Add USER instruction |
Skill("dockerfile-basics")
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.