AI Intermediate: Infrastructure & Agentic SystemsDay 3 of 30 · Week 1: Bare-Metal Infrastructure & Advanced Containerization
Course outline▾

Week 1 · Bare-Metal Infrastructure & Advanced Containerization

  1. Day 1The AI Infrastructure Shift — Why the Model is Only 10% of the Production System
  2. Day 2Advanced Docker for AI — Multi-Stage Builds for Heavy Python Runtimes
  3. Day 3Hardware Acceleration in Docker — GPU Passthrough and Limits for Constrained Hardware
  4. Day 4Optimizing Model Weights: Quantization Basics (GGUF, AWQ) for Efficient Inference
  5. Day 5Local AI Runtimes: Deploying Ollama and vLLM for Bare-Metal Execution
  6. Day 6Containerizing AI Microservices: Building and Packaging APIs with FastAPI
  7. Day 7Docker Compose: Architecting a Multi-Container Database and Inference Stack Locally

Week 2 · Kubernetes Foundation for MLOps

  1. Day 8K3d & Lightweight Kubernetes: Running Multi-Node Clusters on 16GB of RAM
  2. Day 9Kubernetes Core for Machine Learning: Pods, Deployments, and Headless Services
  3. Day 10Persistent Volumes (PV/PVC): Managing Heavy Model Weights and Vector Stores
  4. Day 11StatefulSets for Vector Databases: Deploying Milvus or Qdrant in Kubernetes
  5. Day 12Auto-Scaling AI Inference: Using Horizontal Pod Autoscalers (HPA) for Spiky API Traffic
  6. Day 13Helm Charts: Packaging, Versioning, and Updating AI Deployments
  7. Day 14Week 2 Capstone: Deploying a Highly Available Local AI Application on K3d

Week 3 · High-Performance Networking & Security Mesh

  1. Day 15AI Network Bottlenecks: Transitioning from iptables to eBPF
  2. Day 16Cilium & eBPF: Sub-Millisecond Routing for Heavy AI Microservices
  3. Day 17Service Mesh 101: Installing Istio over Your Local Cluster
  4. Day 18Envoy Proxy as an AI Gateway: Load Balancing and Terminating LLM Prompts
  5. Day 19Zero-Trust mTLS: Encrypting Traffic Between Autonomous Agents
  6. Day 20API Rate Limiting & Egress Control: Preventing Agents from Exfiltrating Data
  7. Day 21Distributed Tracing: Debugging Agent Workflows with Jaeger and OpenTelemetry

Week 4 · Enterprise Agents & CI/CD Workflows

  1. Day 22Introduction to MLOps: Bridging AI Development with Continuous Integration
  2. Day 23GitOps with ArgoCD: Automated, Self-Healing AI Deployments
  3. Day 24Building Ephemeral AI Sandboxes: Secure Execution Environments for Agent Code
  4. Day 25Multi-Agent Orchestration Frameworks: Exploring Mastra, LangGraph, and CrewAI
  5. Day 26Tool-Calling in Production: Connecting Agents Securely to Internal Databases
  6. Day 27MLOps Guardrails: Evaluating Agents and Preventing Hallucinations in Real-Time
  7. Day 28Continuous Training Pipelines: Connecting Data Ingestion to Automated Model Retraining
  8. Day 29Managing Technical Debt and Infrastructure Drift in Enterprise AI
  9. Day 30The AI-Native Platform: Scaling from a Sandbox Environment to Global Cloud Architecture
Open the course page →

Day 3: Hardware Acceleration in Docker — GPU Passthrough and Limits for Constrained Hardware

2026-11-09 · 9 min read

A leading reason AI workloads fail in containers is the boundary between the container's isolated namespace and the host's hardware. Running inference on raw CPUs creates big latency bottlenecks, and exposing a GPU or accelerator takes deliberate host setup.

The acceleration architecture

A container cannot talk to a PCIe device without driver support. The NVIDIA Container Toolkit supplies it by wrapping the standard runtime with a hardware-aware one (nvidia-container-runtime).

HOW A CONTAINER REACHES THE GPUCONTAINER · user spacePyTorch · vLLM · OllamaCUDA runtimelibcudart.so (in the image)libcuda.so + /dev/nvidia*injected at launchHOST · kernel spaceNVIDIA Container Toolkitnvidia-container-runtimekernel drivernvidia.koNVIDIA GPUTensor Cores, over PCIeThe host owns the driver. The image only needs the CUDA runtime.
FIG 1 · The NVIDIA Container Toolkit injects the host's driver libraries and device nodes into the container at launch. Your image does not bundle the kernel driver.

Three ideas make it work.

THREE IDEAS THAT MAKE PASSTHROUGH WORK1DRIVER DECOUPLINGThe host runs the kernel driver. The container never contains it.2RUNTIME INJECTIONAt launch the toolkit mounts libcuda.so and /dev/nvidia* into thecontainer.3APPLICATION AGILITYThe image needs only the high-level CUDA runtime, so it moves betweenhosts with different driver builds.The host driver must still be new enough for the CUDA version in your image.
FIG 2 · Decoupling the driver from the image is what makes accelerated containers portable. Compatibility between the host driver and your image's CUDA version still matters.
  1. Driver decoupling. The host runs the kernel driver (nvidia.ko). The image never contains it.
  2. Runtime injection. At launch the toolkit injects the matching user-space driver library (libcuda.so) and the device nodes (/dev/nvidia*) into the container.
  3. Application agility. The image needs only the high-level CUDA runtime libraries, so it does not depend on the host's driver build. The host driver must still be recent enough for the CUDA version inside the image.

Launching an accelerated container

With the toolkit installed, register it with Docker and restart the daemon.

sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

That edits /etc/docker/daemon.json. You can also set it by hand, and making it the default runtime is optional, since --gpus selects it per container.

{
  "default-runtime": "nvidia",
  "runtimes": {
    "nvidia": { "path": "nvidia-container-runtime", "runtimeArgs": [] }
  }
}
docker run -d --name local-inference \
  --gpus all \
  --shm-size="2g" \
  -p 8000:8000 \
  enterprise-model-server:latest

Verify it: docker run --rm --gpus all ubuntu nvidia-smi should print the same GPU table as the host.

Why --shm-size matters

PyTorch passes tensors between worker processes through shared memory (/dev/shm). Docker's default is only 64 MB, so parallel data loading can crash suddenly with bus errors. Raising it, for example to 2g, avoids that.

WHY --shm-size MATTERS FOR PYTORCHDataLoader workersseveral processes/dev/shmshared memoryTensorspassed between processesDOCKER DEFAULT: 64 MBparallel tensor work fills it→ sudden crashes, Bus error--shm-size="2g"room for multi-process loading→ stable training and inferencedocker run --gpus all --shm-size="2g" -p 8000:8000 model-server
FIG 4 · PyTorch uses shared memory to pass tensors between worker processes. Docker's 64 MB default is too small for that, so raise it with --shm-size.

Hard limits for a 16 GB machine

An unconstrained container is a danger to the host. A multi-step prompt can grow the KV-cache and demand several extra gigabytes of RAM at once, so enforce limits with Linux cgroups.

docker run -d --name constrained-model \
  --cpus="4.0" \
  --memory="10g" \
  --memory-swap="10g" \
  -p 11434:11434 \
  ollama/ollama:latest
A 16 GB HOST: BUDGET THE MEMORY10 GBcontainer cap --memory=10g6 GBhost OS, daemons, cacheWHAT THE FLAGS DO--memory=10ghard cap on RAM for the container--memory-swap=10gequal to memory, so no swap: swapping weights to disk is far slower--cpus=4.0at most 4 cores of CPU timeOOM behaviourpast the cap the kernel stops the container, not the whole hostA KV-cache spike hits the 10 GB cap: only this container is restarted.
FIG 3 · An unconstrained model container can take the whole machine down. Kernel cgroup limits keep the damage inside the container. The 10 GB cap is an example for a 16 GB host.
  • --memory="10g" caps the container at 10 GB and leaves about 6 GB for the host OS, networking daemons and file cache.
  • --memory-swap="10g" (equal to --memory) disables swap for the container. Swapping model weights to disk slows inference by orders of magnitude, so it is better to fail fast.
  • When the container exceeds its cap, the kernel's OOM killer stops that container, not the host. This is the default behaviour (--oom-kill-disable=false), so you do not need to set it. Never use --oom-kill-disable=true without a memory limit, because then a spike can hang the whole machine.
  • Add --gpus only when a GPU is present. On a CPU-only laptop, the memory and CPU caps are what protect you.

Treat these flags as part of your deployment definition, and in Kubernetes you will express the same limits as resource requests and limits.

Run it yourself

This is the exact example from the video. These are real docker run commands that read the limits from inside the container. There is no GPU on my laptop, so only the limits half of the lesson is shown.

# no GPU on this machine, so limits only
docker run --rm --cpus=2 --memory=256m --memory-swap=256m \
  --shm-size=2g alpine:3.20 sh -c '
  cd /sys/fs/cgroup
  for f in memory.max memory.swap.max cpu.max; do
    echo "$f: $(cat $f)"
  done
  echo shm: $(df -h /dev/shm | tail -1 | tr -s " " | cut -d" " -f2)'

docker run --rm --memory=64m --memory-swap=64m alpine:3.20 \
  sh -c 'x=$(dd if=/dev/zero bs=1M count=200 | tr "\0" x)'
echo "over the cap: exit code $?"

Run it:

bash limits.sh

Output I got while recording the video:

memory.max: 268435456
memory.swap.max: 0
cpu.max: 200000 100000
shm: 2.0G
over the cap: exit code 137

Coming Up Next

Day 4: Optimising model weights: quantization basics with GGUF and AWQ.

#HardwareAcceleration #Docker #GPUs #DevOps #Linux #TechInfrastructure #CUDA #SystemAdministration