This repository focuses on mastering containerization technologies using Docker, Kubernetes, and related tools to build, manage, and automate container infrastructure for Internal Development Platform (IDP) development.
By working through this repository, you will:
- Master Docker container creation and management
- Implement multi-stage builds and optimization
- Work with Docker Compose for multi-container applications
- Understand Kubernetes architecture and concepts
- Deploy and manage applications on Kubernetes
- Implement container security best practices
- Build CI/CD pipelines for containerized applications
- Python 3.11 or higher
- Docker Desktop installed
- kubectl installed
- Basic understanding of Linux and networking
- Completed learning-idp-python-azure-sdk
- Git and GitHub account
learning-idp-containerization/ βββ README.md # This file βββ REFERENCES.md # Links to resources and related repos βββ pyproject.toml # Python project configuration βββ requirements.txt # Python dependencies βββ requirements-dev.txt # Development dependencies βββ .python-version # Python version for pyenv βββ .gitignore # Git ignore patterns βββ .env.example # Environment variables template β βββ docs/ β βββ concepts/ β β βββ 01-containerization-overview.md β β βββ 02-docker-fundamentals.md β β βββ 03-kubernetes-architecture.md β β βββ 04-container-networking.md β β βββ 05-container-storage.md β β βββ 06-container-security.md β βββ guides/ β β βββ getting-started.md β β βββ dockerfile-best-practices.md β β βββ kubernetes-deployment.md β β βββ helm-charts.md β β βββ container-registry.md β βββ examples/ β βββ simple-dockerfile.md β βββ multi-stage-build.md β βββ kubernetes-deployment.md β βββ stateful-application.md β βββ microservices-architecture.md β βββ src/ β βββ __init__.py β β β βββ core/ β β βββ __init__.py β β βββ authentication.py # Docker/K8s authentication β β βββ config.py # Configuration management β β βββ exceptions.py # Custom exceptions β β βββ logging_config.py # Logging setup β β β βββ docker/ β β βββ __init__.py β β βββ docker_client.py # Docker API client β β βββ image_builder.py # Image building β β βββ container_manager.py # Container management β β βββ network_manager.py # Network operations β β βββ volume_manager.py # Volume operations β β β βββ compose/ β β βββ __init__.py β β βββ compose_manager.py # Docker Compose operations β β βββ service_scaler.py # Service scaling β β βββ health_checker.py # Health monitoring β β β βββ kubernetes/ β β βββ __init__.py β β βββ k8s_client.py # Kubernetes client β β βββ deployment_manager.py # Deployment operations β β βββ service_manager.py # Service management β β βββ pod_manager.py # Pod operations β β βββ namespace_manager.py # Namespace management β β β βββ helm/ β β βββ __init__.py β β βββ helm_client.py # Helm operations β β βββ chart_manager.py # Chart management β β βββ release_manager.py # Release operations β β β βββ registry/ β β βββ __init__.py β β βββ acr_manager.py # Azure Container Registry β β βββ dockerhub_manager.py # Docker Hub operations β β βββ registry_scanner.py # Security scanning β β β βββ security/ β β βββ __init__.py β β βββ image_scanner.py # Image security scanning β β βββ secret_manager.py # Secret management β β βββ policy_enforcer.py # Security policies β β βββ rbac_manager.py # RBAC configuration β β β βββ monitoring/ β βββ __init__.py β βββ metrics_collector.py # Container metrics β βββ log_aggregator.py # Log collection β βββ health_monitor.py # Health checks β βββ examples/ β βββ 01_docker_basics/ β β βββ 01_simple_dockerfile/ β β β βββ Dockerfile β β β βββ app.py β β β βββ requirements.txt β β βββ 02_multi_stage_build/ β β β βββ Dockerfile β β β βββ app.py β β βββ 03_docker_compose/ β β β βββ docker-compose.yml β β β βββ web/Dockerfile β β β βββ db/init.sql β β βββ 04_networking/ β β β βββ docker-compose.yml β β βββ 05_volumes/ β β βββ docker-compose.yml β β β βββ 02_docker_python/ β β βββ 01_flask_app/ β β β βββ Dockerfile β β β βββ app.py β β β βββ requirements.txt β β βββ 02_fastapi_app/ β β β βββ Dockerfile β β β βββ main.py β β β βββ requirements.txt β β βββ 03_celery_worker/ β β β βββ docker-compose.yml β β β βββ worker/Dockerfile β β β βββ tasks.py β β βββ 04_ml_model/ β β βββ Dockerfile β β βββ model.py β β β βββ 03_kubernetes_basics/ β β βββ 01_pod.yaml β β βββ 02_deployment.yaml β β βββ 03_service.yaml β β βββ 04_configmap.yaml β β βββ 05_secret.yaml β β βββ 06_ingress.yaml β β β βββ 04_kubernetes_advanced/ β β βββ 01_statefulset.yaml β β βββ 02_daemonset.yaml β β βββ 03_job.yaml β β βββ 04_cronjob.yaml β β βββ 05_hpa.yaml β β βββ 06_network_policy.yaml β β β βββ 05_helm_charts/ β β βββ simple-app/ β β β βββ Chart.yaml β β β βββ values.yaml β β β βββ templates/ β β β βββ deployment.yaml β β β βββ service.yaml β β β βββ ingress.yaml β β βββ microservices/ β β βββ Chart.yaml β β βββ values.yaml β β βββ templates/ β β β βββ 06_container_registry/ β β βββ 01_push_to_acr.py β β βββ 02_scan_image.py β β βββ 03_manage_tags.py β β βββ 04_cleanup_old_images.py β β β βββ 07_security/ β β βββ 01_image_scanning.py β β βββ 02_secret_management.py β β βββ 03_network_policies.yaml β β βββ 04_pod_security.yaml β β βββ 05_rbac_setup.yaml β β β βββ 08_cicd/ β βββ 01_github_actions/ β β βββ docker-build.yml β βββ 02_azure_devops/ β β βββ azure-pipelines.yml β βββ 03_gitops/ β βββ argocd-application.yaml β βββ templates/ β βββ dockerfiles/ β β βββ python-base.Dockerfile β β βββ python-alpine.Dockerfile β β βββ nodejs-base.Dockerfile β β βββ multi-stage.Dockerfile β βββ compose/ β β βββ web-db-redis.yml β β βββ microservices.yml β β βββ monitoring-stack.yml β βββ kubernetes/ β β βββ deployment-template.yaml β β βββ service-template.yaml β β βββ ingress-template.yaml β βββ helm/ β βββ chart-skeleton/ β βββ notebooks/ β βββ 01_docker_basics.ipynb β βββ 02_kubernetes_intro.ipynb β βββ 03_helm_charts.ipynb β βββ 04_security_practices.ipynb β βββ 05_monitoring_containers.ipynb β βββ scripts/ β βββ setup_docker.sh # Docker setup script β βββ setup_kubernetes.sh # Kubernetes setup β βββ build_images.sh # Build all images β βββ deploy_to_k8s.sh # Deploy to Kubernetes β βββ cleanup.sh # Resource cleanup β βββ tests/ β βββ __init__.py β βββ conftest.py β βββ unit/ β β βββ test_docker_client.py β β βββ test_k8s_client.py β β βββ test_helm_client.py β βββ integration/ β βββ test_container_lifecycle.py β βββ test_deployment.py β βββ test_networking.py β βββ .github/ βββ workflows/ βββ docker-build.yml # Docker build workflow βββ k8s-deploy.yml # Kubernetes deployment βββ security-scan.yml # Security scanning git clone https://github.com/vanHeemstraSystems/learning-idp-containerization.git cd learning-idp-containerization# Install Docker Desktop # Download from: https://www.docker.com/products/docker-desktop # Install kubectl curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl # Install Helm curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash # Set up Python environment python3 -m venv venv source venv/bin/activate pip install -r requirements.txt# Build a simple Docker image cd examples/01_docker_basics/01_simple_dockerfile docker build -t my-first-app . # Run the container docker run -p 8000:8000 my-first-app # Test it curl http://localhost:8000# Enable Kubernetes in Docker Desktop or use Minikube minikube start # Deploy a simple application kubectl apply -f examples/03_kubernetes_basics/02_deployment.yaml kubectl apply -f examples/03_kubernetes_basics/03_service.yaml # Check the deployment kubectl get pods kubectl get servicesFollow this recommended sequence:
Day 1-2: Docker Basics
- Read
docs/concepts/02-docker-fundamentals.md - Work through
examples/01_docker_basics/ - Practice building and running containers
Day 3-4: Dockerfile Best Practices
- Study
docs/guides/dockerfile-best-practices.md - Complete examples in
examples/02_docker_python/ - Implement multi-stage builds
Day 5-7: Docker Compose
- Work through Docker Compose examples
- Build multi-container applications
- Practice service networking
Day 1-3: Kubernetes Architecture
- Read
docs/concepts/03-kubernetes-architecture.md - Complete examples in
examples/03_kubernetes_basics/ - Deploy applications to Kubernetes
Day 4-7: Advanced Kubernetes
- Work through
examples/04_kubernetes_advanced/ - Implement StatefulSets and DaemonSets
- Configure autoscaling
Day 1-3: Container Registry
- Complete examples in
examples/06_container_registry/ - Push images to Azure Container Registry
- Implement image scanning
Day 4-7: Security Best Practices
- Study
docs/concepts/06-container-security.md - Work through
examples/07_security/ - Implement security policies
Day 1-3: Helm Charts
- Read
docs/guides/helm-charts.md - Create custom Helm charts
- Deploy with Helm
Day 4-7: CI/CD Integration
- Work through
examples/08_cicd/ - Build container CI/CD pipelines
- Implement GitOps workflows
# Docker docker>=24.0.0 # Kubernetes kubectl>=1.28.0 # Helm helm>=3.13.0 # Python Libraries docker>=7.0.0 # Docker SDK for Python kubernetes>=28.1.0 # Kubernetes Python client# Multi-stage build for Python application FROM python:3.11-slim as builder WORKDIR /app # Install dependencies COPY requirements.txt . RUN pip install --user --no-cache-dir -r requirements.txt # Final stage FROM python:3.11-slim WORKDIR /app # Copy dependencies from builder COPY --from=builder /root/.local /root/.local # Copy application code COPY . . # Make sure scripts in .local are usable ENV PATH=/root/.local/bin:$PATH # Non-root user RUN useradd -m appuser && chown -R appuser:appuser /app USER appuser EXPOSE 8000 CMD ["python", "app.py"]version: '3.8' services: web: build: ./web ports: - "8000:8000" environment: - DATABASE_URL=postgresql://db:5432/myapp - REDIS_URL=redis://redis:6379 depends_on: - db - redis networks: - app-network healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8000/health"] interval: 30s timeout: 10s retries: 3 db: image: postgres:16-alpine environment: - POSTGRES_DB=myapp - POSTGRES_PASSWORD=secretpassword volumes: - postgres-data:/var/lib/postgresql/data networks: - app-network redis: image: redis:7-alpine volumes: - redis-data:/data networks: - app-network volumes: postgres-data: redis-data: networks: app-network: driver: bridgefrom kubernetes import client, config # Load kubeconfig config.load_kube_config() # Create API clients apps_v1 = client.AppsV1Api() core_v1 = client.CoreV1Api() # Define deployment deployment = client.V1Deployment( metadata=client.V1ObjectMeta(name="my-app"), spec=client.V1DeploymentSpec( replicas=3, selector=client.V1LabelSelector( match_labels={"app": "my-app"} ), template=client.V1PodTemplateSpec( metadata=client.V1ObjectMeta( labels={"app": "my-app"} ), spec=client.V1PodSpec( containers=[ client.V1Container( name="my-app", image="myregistry.azurecr.io/my-app:latest", ports=[client.V1ContainerPort(container_port=8000)], resources=client.V1ResourceRequirements( requests={"cpu": "100m", "memory": "128Mi"}, limits={"cpu": "500m", "memory": "512Mi"} ), liveness_probe=client.V1Probe( http_get=client.V1HTTPGetAction( path="/health", port=8000 ), initial_delay_seconds=10, period_seconds=10 ) ) ] ) ) ) ) # Create deployment apps_v1.create_namespaced_deployment( namespace="default", body=deployment ) # Create service service = client.V1Service( metadata=client.V1ObjectMeta(name="my-app"), spec=client.V1ServiceSpec( selector={"app": "my-app"}, ports=[client.V1ServicePort(port=80, target_port=8000)], type="LoadBalancer" ) ) core_v1.create_namespaced_service( namespace="default", body=service ) print("Deployment and service created successfully")import os from pathlib import Path def create_helm_chart(chart_name: str, output_dir: str): """Create a basic Helm chart structure""" chart_path = Path(output_dir) / chart_name # Create directory structure (chart_path / "templates").mkdir(parents=True, exist_ok=True) # Chart.yaml chart_yaml = f"""apiVersion: v2 name: {chart_name} description: A Helm chart for {chart_name} type: application version: 0.1.0 appVersion: "1.0" """ # values.yaml values_yaml = """replicaCount: 3 image: repository: myregistry.azurecr.io/my-app tag: latest pullPolicy: IfNotPresent service: type: ClusterIP port: 80 ingress: enabled: false resources: limits: cpu: 500m memory: 512Mi requests: cpu: 100m memory: 128Mi autoscaling: enabled: true minReplicas: 2 maxReplicas: 10 targetCPUUtilizationPercentage: 80 """ # Write files (chart_path / "Chart.yaml").write_text(chart_yaml) (chart_path / "values.yaml").write_text(values_yaml) print(f"Helm chart created at: {chart_path}") # Create chart create_helm_chart("my-app", "./helm-charts")import docker import json def scan_image(image_name: str): """Scan Docker image for vulnerabilities using Trivy""" client = docker.from_env() # Pull image if not exists try: client.images.get(image_name) except docker.errors.ImageNotFound: print(f"Pulling image: {image_name}") client.images.pull(image_name) # Run Trivy scan result = client.containers.run( "aquasec/trivy:latest", f"image --format json {image_name}", remove=True, volumes={ "/var/run/docker.sock": { "bind": "/var/run/docker.sock", "mode": "ro" } } ) # Parse results scan_results = json.loads(result) # Count vulnerabilities vulnerabilities = { "CRITICAL": 0, "HIGH": 0, "MEDIUM": 0, "LOW": 0 } for target in scan_results.get("Results", []): for vuln in target.get("Vulnerabilities", []): severity = vuln.get("Severity", "UNKNOWN") if severity in vulnerabilities: vulnerabilities[severity] += 1 print(f"\nVulnerability Scan Results for {image_name}:") print(f"CRITICAL: {vulnerabilities['CRITICAL']}") print(f"HIGH: {vulnerabilities['HIGH']}") print(f"MEDIUM: {vulnerabilities['MEDIUM']}") print(f"LOW: {vulnerabilities['LOW']}") return vulnerabilities # Scan image scan_image("python:3.11-slim")# Use specific version tags FROM python:3.11-slim # Set working directory WORKDIR /app # Copy only requirements first (layer caching) COPY requirements.txt . # Install dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . # Use non-root user RUN useradd -m appuser && chown -R appuser:appuser /app USER appuser # Document exposed ports EXPOSE 8000 # Use exec form for CMD CMD ["python", "app.py"]resources: requests: cpu: "100m" memory: "128Mi" limits: cpu: "500m" memory: "512Mi"livenessProbe: httpGet: path: /health port: 8000 initialDelaySeconds: 10 periodSeconds: 10 readinessProbe: httpGet: path: /ready port: 8000 initialDelaySeconds: 5 periodSeconds: 5# Run as non-root USER 1000:1000 # Read-only root filesystem securityContext: readOnlyRootFilesystem: true runAsNonRoot: true runAsUser: 1000- learning-internal-development-platform - Main overview
- learning-idp-python-azure-sdk - Azure SDK fundamentals
- learning-idp-azure-compute - AKS integration
- learning-idp-cicd-pipelines - Container CI/CD
- learning-idp-observability - Container monitoring
This is a personal learning repository, but suggestions and improvements are welcome!
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Ensure all tests pass
- Submit a pull request
This project is for educational purposes. See LICENSE file for details.
Willem van Heemstra
- GitHub: @vanHeemstraSystems
- LinkedIn: Willem van Heemstra
Last updated: December 18, 2025 Part of the learning-internal-development-platform series