BLOG06: Containerization Concepts
BLOG15: Containerization Concepts
Can we simulate container environment manually?
1. Building a final image by combining multiple image layers (Overlaying graphics)
Example with Python (Pillow library)
from PIL import Image
base = Image.open("layers/base/background.png").convert("RGBA")
layer1 = Image.open("layers/body/body1.png").convert("RGBA")
layer2 = Image.open("layers/head/head3.png").convert("RGBA")
layer3 = Image.open("layers/accessories/hat2.png").convert("RGBA")
final = Image.alpha_composite(base, layer1)
final = Image.alpha_composite(final, layer2)
final = Image.alpha_composite(final, layer3)
final.save("output/final.png")2. Using Docker to build an image from folders (Docker layering)
3. Building a filesystem image (ISO, squashfs, qcow2) by overlaying folders
OverlayFS (Linux)
mksquashfs
Part 1: Understand How Docker Images Work
Part 2: Manually Build a Root Filesystem
1. Create working directories
2. Populate a base filesystem
3. Create required dev nodes (minimal)
Part 3: Verify it works (optional)
Part 4: Create a Docker Layer (layer.tar)
Part 5: Create the Docker metadata
manifest.json
config.json
Part 6: Import the Image into Docker
Part 7: Build More Layers (Optional)
Summary
Step
What you did
1. Quick Overview: How Docker Uses OverlayFS
2. Manually Overlay Two Folders (Like Docker Does)
Step 1: Create lower (base image layer)
Step 2: Create upper (container's writable layer)
Step 3: Create work + merged dirs
Step 4: Mount Overlay
3. Check the Top (Merged) View
4. OverlayFS Delete Example (Docker Whiteout)
5. Compare With How Docker Does It
6. Multi-layer Overlay Example (like Docker Image Layers)
7. Why merged view feels like "final Docker image"
Summary
Concept
Meaning
How Docker Networking Works Internally
STEP 1: Create a Network Namespace (Container Equivalent)
STEP 2: Create a veth Pair (Like Docker Does)
STEP 3: Move One End Into the Namespace
STEP 4: Create docker0 Bridge (Docker Default Network)
STEP 5: Attach veth0 to the Bridge
STEP 6: Set IP Inside Container Namespace
STEP 7: Bring Up Loopback in Namespace
STEP 8: Set Default Route (Like Docker Does)
TEST: Ping Host from Container Namespace
TEST: Ping Between Containers
STEP 9: Enable NAT (Docker Does This)
TEST: Ping Google DNS (8.8.8.8)
Summary
Component
Manual Equivalent
Docker User Process Isolation using Linux Namespaces + cgroups
1. Launch a Process in New Namespaces (container-like)
Smallest "container" ever:
Flag
Namespace
2. Set a Hostname (UTS Namespace)
3. Create an Isolated Root Filesystem (mount namespace)
4. Combine Namespaces + Chroot → Full Minimal Container
5. Add cgroups → Resource limits (like docker run --cpus 1 --memory=256m)
docker run --cpus 1 --memory=256m)6. Understanding Docker in 1 Sentence
1. prepare filesystems
2. prepare networking
3. isolate namespaces
4. apply cgroups
5. run process inside isolation
Final Full Example: Starting a Process in "Container Mode"
Next Steps
How Docker uses containerd + runc + OCI runtime spec
How docker run translates into runc commands
docker run translates into runc commandsBuild your own container runtime (40 lines of Go!)
How Docker namespaces map to docker inspect output
docker inspect outputHow Docker really launches a container under the hood using containerd + runc + OCI bundle
1. Docker Architecture in Reality
2. runc Needs an OCI Bundle (RootFS + Config)
3. Create a Minimal Root Filesystem
4. Generate a Default OCI Config
5. Modify config.json to run a command
6. Run the Container Using ONLY runc
7. Summary of what has been built:
Component
Docker Does
You Did
8. Compare With What Docker Would Run
1. Docker Volumes Overview
Feature
Description
2. Where Docker Stores Volumes on the Host
3. Mounting Volume into a Container
4. How This Works Internally
5. Example: Manual Volume Mount
6. Named vs Bind Mounts
7. Key Takeaways
Concept
Host
Container
Notes
8. How Docker actually does it
1. Containers and Namespaces
2. How a Container Can See Host Files
3. Why it Works Across Namespaces
4. Manual Example Without Docker
5. Key Takeaways
Concept
Detail
Last updated