π³ Docker Mastery
Welcome to Phase 2 of the CI/CD Chaos Workshop β the stage where we dive deep into Docker, learn how to build Python apps properly, and create chaos-worthy Docker images for production!
π What You'll Experience in This Phase
Scenario 01: Streaming Server with Docker
- Launch your own live streaming server using Docker and Owncast.
- Connect OBS Studio, stream video, and share it with the world.
- Learn about containerized media, port mapping, and real-world Docker deployment.
- See how Docker makes complex app stacks portable and reproducible.
Scenario 02: Progressive Chaos Engineering Pipeline
- Enter the world of chaos engineering β safely, in Docker!
- Run a Jenkins pipeline that simulates real-world failures: network outages, resource exhaustion, missing dependencies, and database crashes.
- Watch as each pipeline step introduces a new failure, then learn how to fix it.
- Master Docker-in-Docker (DinD), container orchestration, and resilient CI/CD design.
- Build confidence in troubleshooting and debugging containerized pipelines.
Scenario 03: Docker Networking Magic
- Deploy a live voting app and see how containers communicate (or fail to!).
- Simulate broken networks, missing databases, and container isolation.
- Fix networking issues live and watch your app come to life.
- Learn about Docker networks, bridges, and best practices for multi-container apps.
- Experience the "AHA!" moment when everything just works.
Scenario 04: Docker Image Scanner
- Upload any Dockerfile and get instant, real-world security and best-practices analysis.
- See how Trivy scans for vulnerabilities and how small Dockerfile changes impact security.
- Learn to optimize, harden, and benchmark your images β and get actionable feedback.
- Discover the power of automated image analysis in modern DevOps.
Scenario 05: Docker Escape Room
- Enter a gamified, puzzle-based Docker adventure.
- Solve hands-on challenges: volumes, networking, secrets, resource limits, and multi-stage builds.
- Race against the clock, outsmart Dr. NullPointer, and escape the Docker Vault!
- Experience Docker as a real-world troubleshooting and problem-solving journey.
- Walk away with Docker mastery, confidence, and a smile.
π¬ What You'll Learn
- How to containerize and run real-world apps (media, web, CI/CD, games)
- The art of troubleshooting and debugging Dockerized systems
- Chaos engineering and resilience in pipelines
- Docker networking, volumes, and resource management
- Security scanning and best practices for Dockerfiles
- The fun and power of hands-on, scenario-based learning
This phase is your Docker bootcamp, playground, and proving ground. Get ready to build, break, fix, and master Docker β with a little chaos and a lot of fun!
π What We're Building
We're developing a FastAPI Python app:
- 5 different versions
- Each with new features, animations, or visuals
- Deployed via Docker
- Automatically analyzed for:
- image size
- layer count
- base image details
Chaos Agent says: "Let's bloat those images!"
Our mission: keep images lean and secure.
β¨ How to Deploy Versions
Instead of manually switching files and building containers, we've automated everything!
Run:
python Docker/workshop_tools/deploy_version.py 3
β This:
- Copies the correct
main_vX.pytomain.py - Builds your Docker image
- Stops/removes any container running on port 3000
- Runs the new version
- Generates a beautiful HTML Docker report under:
reports/version_3/docker_report.html
π Docker Analysis Reports
Every deploy automatically runs:
python Docker/workshop_tools/generate_docker_report.py 3
This analyzes:
β
Image size (MB)
β
Number of layers
β
Base image used
β
Recommendations for optimization
It creates a report like:
Why it matters: This makes Docker transparent for developers and helps avoid bloat.
π Demo Scenarios
During the workshop, we'll:
β
Deploy version 1 β tiny image
β
Deploy version 2 β adds emojis β image grows
β
Deploy version 3 β multi-stage build β image shrinks
β
Deploy version 4 β adds background workers β image grows
β
Deploy version 5 β chaos animations β biggest image
We'll learn how to:
- Avoid large images
- Use
.dockerignoreeffectively - Minimize layers
- Prefer multi-stage builds
- Separate dev vs prod images
Chaos Agent's trap:
"Add one more pip install⦠what's the harm?"
We'll prove why that's dangerous.
π€Ή Why Multi-Stage Builds Matter
Without multi-stage:
- Images ~400MB or more
- Contains unnecessary build tools
- Slower deployments
With multi-stage:
- Images ~100MB or less
- Production only includes:
- compiled Python code
- minimal runtime packages
- Fewer attack surfaces
Example Dockerfile:
# First stage
FROM python:3.12-slim AS builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
# Second stage
FROM python:3.12-slim
WORKDIR /app
COPY --from=builder /install /usr/local
COPY ./app ./app
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "3000"]
Best Practice: Keep the runtime image as slim as possible.
π‘ Tips for Workshop Demos
β Show Docker image size differences:
docker images
β Check layer digests:
docker inspect ci-cd-chaos-app:v3
β Show Docker build history:
docker history ci-cd-chaos-app:v3
β Explain why small images deploy faster.
β Highlight how multi-stage prevents secrets from leaking into final images.
Chaos Agent:
"Let's leave secrets in the image. No one will find themβ¦"
We'll prove how scanning tools and image inspection can expose secrets.
π₯ Chaos Engineering with Docker
Optional chaos ideas:
- Randomly build incorrect versions
- Introduce slow builds to show Docker caching
- Simulate Docker build errors
- Show how CI/CD detects Docker issues early
Mission: Prove that pipelines protect you from Docker chaos.
β Run It All Together
To deploy version 5 and see the full chaos experience:
python Docker/workshop_tools/deploy_version.py --version 5
Then check:
# View the running app
curl http://localhost:3000
# Check the Docker report
open reports/version_5/docker_report.html
π§ͺ Chaos Testing Scenarios
β Scenario 1: Docker Build Failures
# Simulate Docker build failures
docker build --no-cache -t chaos-app:broken .
# Expected: Build fails due to missing dependencies
β Scenario 2: Image Size Explosion
# Compare image sizes
docker images chaos-app --format "table {{.Tag}}\t{{.Size}}"
# Expected: Version 5 should be significantly larger than Version 1
β Scenario 3: Security Vulnerabilities
# Scan for vulnerabilities
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
aquasec/trivy image chaos-app:v1
# Expected: Find potential security issues
π Monitoring & Reporting
β Docker Metrics
- Image build time
- Image size trends
- Layer count analysis
- Security vulnerability count
β Chaos Metrics
- Build failure rate
- Image size explosion rate
- Security issue detection rate
π― Next Steps
β
Phase 2 Complete: You now have Docker mastery!
β
Ready for Phase 3: Jenkins Pipeline Chaos
β
Chaos Agent Status: Defeated in Docker optimization! πΆοΈ
Remember: Docker is your first line of defense against deployment chaos. Keep images lean, secure, and fast! π₯