dockerfile-basics
Learn Dockerfile fundamentals and best practices for building production-ready container images
What this skill does
# Dockerfile Basics Skill
Master Dockerfile fundamentals and 2024-2025 best practices for building secure, optimized container images.
## Purpose
Provide comprehensive guidance on Dockerfile syntax, instruction ordering, layer optimization, and security best practices.
## Parameters
| 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 |
## Core Instructions
### Instruction Reference
| 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/` |
### Layer Optimization Order
```dockerfile
# 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"]
```
## Best Practices (2024-2025)
### Security Essentials
```dockerfile
# 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 ./
```
### Optimization Techniques
```dockerfile
# 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 Handling
### Common Errors
| 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 |
### Validation Commands
```bash
# Lint Dockerfile
hadolint Dockerfile
# Build with no cache
docker build --no-cache -t app:test .
# Inspect layers
docker history app:test
```
## Troubleshooting
### Debug Checklist
- [ ] .dockerignore excludes unnecessary files?
- [ ] Base image tag is specific (not :latest)?
- [ ] Dependencies copied before source code?
- [ ] Non-root user configured?
- [ ] HEALTHCHECK defined?
### Common Issues
| 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 |
## Usage
```
Skill("dockerfile-basics")
```
## Related Skills
- docker-multi-stage
- docker-optimization
- docker-security
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.