Code samples to accompany the article: “Mastering Docker Build Contexts and Architecture”.
This repo demonstrates common scenarios, best practices, and pitfalls of Docker builds.
Each folder contains its own Dockerfile, source files, and a README.md with usage instructions.
- Folder: 01-node-local-context
- Description: Node.js app using local build context, optimized with
.dockerignoreand proper layer caching.
- Folder: 02-python-cache
- Description: Python app demonstrating dependency caching with
requirements.txt.
- Folder: 03-multistage-node
- Description: Node.js build stage → Nginx production stage for smaller images.
- Folder: 04-wrong-context
- Description: Example of incorrect context usage (
../sharedoutside build context) and how to fix it.
- Folder: 05-dockerignore-optimization
- Description: Shows the impact of ignoring large, unnecessary files for faster builds.
- Folder: 06-build-secrets
- Description: Using BuildKit secrets (
--secret) to keep API keys and sensitive data out of image layers.
- Folder: 07-named-contexts
- Description: Demonstrates pulling in files from multiple named contexts.
- Folder: 08-empty-context-and-comms
- Description:
- Empty context builds (
docker build - < Dockerfile) - Stdin builds with args and labels
- Bash + PowerShell scripts
- Buildx ↔ BuildKit communication artifacts (Mermaid diagram, JSON request, resource requests)
- Empty context builds (
Clone repo:
cd docker-build-architecture-examples