Skip to main content

Menu

LEVEL 0
0/5 XP
HomeAboutTopicsPricingMy VaultStats

Categories

🤖 Artificial Intelligence
☁️ Cloud and Infrastructure
💾 Data and Databases
💼 Professional Skills
🎯 Programming and Development
🔒 Security and Networking
📚 Specialized Topics
HomeAboutTopicsPricingMy VaultStats
LEVEL 0
0/5 XP
GitHub
© 2026 CheatGrid™. All rights reserved.
Privacy PolicyTerms of UseAboutContact

Dockerfile Cheat Sheet

Dockerfile Cheat Sheet

Back to Containers Orchestration
Updated 2026-03-17
Next Topic: Helm Cheat Sheet

A Dockerfile is a text-based script containing sequential instructions for building Docker container images. It lives at the heart of containerization workflows, enabling developers to package applications with all dependencies into portable, reproducible runtime environments. Every instruction in a Dockerfile creates a layer in the final image—understanding layer mechanics, caching behavior, and optimization strategies is critical for building lean, fast, and secure images. Modern Dockerfile authoring relies heavily on multi-stage builds, BuildKit features like cache mounts and heredocs, and security best practices such as non-root execution and minimal base images. The key mental model: treat your Dockerfile as production code—every line impacts image size, build speed, security posture, and runtime behavior.


What This Cheat Sheet Covers

This topic spans 12 focused tables and 80 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.

Table 1: Base Image SelectionTable 2: Core InstructionsTable 3: Build Arguments & Environment VariablesTable 4: Multi-Stage BuildsTable 5: Layer OptimizationTable 6: Caching StrategiesTable 7: Size Reduction TechniquesTable 8: Security HardeningTable 9: Advanced InstructionsTable 10: BuildKit FeaturesTable 11: Multi-Architecture BuildsTable 12: Best Practices & Anti-patterns

Table 1: Base Image Selection

TechniqueExampleDescription
Official images
FROM node:20-alpine
• Use Docker Official Images from verified publishers
• maintained, scanned, and documented by Docker or upstream maintainers.
Alpine Linux
FROM alpine:3.20
• Minimal base image (~5 MB) using musl libc and apk package manager
• excellent for reducing image size but may have compatibility issues with glibc-dependent binaries.
Distroless
FROM gcr.io/distroless/python3
• Google's minimal images containing only runtime dependencies—no shell, package manager, or OS utilities
• drastically reduces attack surface.
Slim variants
FROM python:3.11-slim
• Debian-based images with non-essential packages removed
• balances size reduction with broader compatibility than Alpine.

More in Containers Orchestration

  • Docker Swarm Cheat Sheet
  • Helm Cheat Sheet
  • CaaS (Containers as a Service) Cheat Sheet
  • Container Lifecycle Management Cheat Sheet
  • Container Orchestration Patterns Cheat Sheet
  • Docker Cheat Sheet
View all 19 topics in Containers Orchestration