Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 138/ 160
07. CI/CD, Registries & Production Operations

GPU Acceleration in Docker (NVIDIA Container Toolkit & --gpus all)

Expose GPUs to containers with the NVIDIA Container Toolkit and --gpus flags.

AdvancedNVIDIA Toolkit · --gpus3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Decide visible devices, memory allocation policy and framework CUDA compatibility, then treat GPU failures as driver/runtime/app integration.

Think of it like…

The host installs the highway and toll booths; the container receives a defined set of GPU lanes and carries its framework toolset, not a replacement road system.

Where you’ve seen it

In practice, nvidia-ctk runtime configure --runtime=docker; docker run --rm --gpus "device=0,capabilities=compute,utility" nvidia/cuda:12.6.3-base nvidia-smi is the concrete move for this job: expose GPUs to containers with the NVIDIA Container Toolkit and --gpus flags. The release is not accepted until nvidia-smi inside and outside the container, run a matrix multiply, then verify memory/device visibility and scheduler contention confirms the result.

Words you’ll hear

NVIDIA Toolkit
The implementation control in nvidia-ctk runtime configure --runtime=docker; docker run --rm --gpus "device=0,capabilities=compute,utility" nvidia/cuda:12.6.3-base nvidia-smi for expose GPUs to containers with the NVIDIA Container Toolkit and --gpus flags.
--gpus
The result to observe with nvidia-smi inside and outside the container, run a matrix multiply, then verify memory/device visibility and scheduler contention, rather than infer from a successful command alone.
CUDA
The production boundary exposed when installing an NVIDIA driver inside the image or allocating all GPU memory to one process in a shared node.

Visual diagram

Loading interactive diagram

Theory & deep dive

NVIDIA Toolkit control path

The concrete mechanism is nvidia-ctk runtime configure --runtime=docker; docker run --rm --gpus "device=0,capabilities=compute,utility" nvidia/cuda:12.6.3-base nvidia-smi. The observable result is nvidia-smi inside and outside the container, run a matrix multiply, then verify memory/device visibility and scheduler contention; if those disagree, inspect the runtime evidence before changing unrelated settings.

Expose GPUs to containers with the NVIDIA Container Toolkit and --gpus flags. Keep NVIDIA Toolkit, --gpus and CUDA in the same deployment record so the intent and the observed state cannot drift apart.

Concrete NVIDIA Toolkit setup

nvidia-ctk runtime configure --runtime=docker; docker run --rm --gpus "device=0,capabilities=compute,utility" nvidia/cuda:12.6.3-base nvidia-smi

Key takeaway: Prove --gpus with nvidia-smi inside and outside the container, run a matrix multiply, then verify memory/device visibility and scheduler contention, not with command success alone.

CUDA failure boundary

A CPU-only CI host cannot validate GPU behavior, and --gpus all gives every device to one model server. MIG slices, compute modes and shared memory vary by hardware; CUDA toolkit/library ABI errors often appear only at runtime. The narrow failure to design for is installing an NVIDIA driver inside the image or allocating all GPU memory to one process in a shared node.

Accept this compromise explicitly: Device-specific allocation maximizes isolation; all-GPU access is simple but prevents concurrent placement and capacity accounting. The controlled check-nvidia-smi inside and outside the container, run a matrix multiply, then verify memory/device visibility and scheduler contention-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: installing an NVIDIA driver inside the image or allocating all GPU memory to one process in a shared node.

Key takeaway: Device-specific allocation maximizes isolation; all-GPU access is simple but prevents concurrent placement and capacity accounting.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: A CPU-only CI host cannot validate GPU behavior, and --gpus all gives every device to one model server. MIG slices, compute modes and shared memory vary by hardware; CUDA toolkit/library ABI errors often appear only at runtime.

Decide visible devices, memory allocation policy and framework CUDA compatibility, then treat GPU failures as driver/runtime/app integration.
Key numbers at this step
Intent
NVIDIA Toolkit

When to use it & trade-offs

What it is

NVIDIA Container Toolkit configures the OCI runtime to expose host GPU devices, driver libraries and cgroup/namespace support. --gpus controls requested devices and capabilities; an image must match the host driver/compute compatibility without attempting to ship a Linux kernel driver.

Why it matters: A CPU-only CI host cannot validate GPU behavior, and --gpus all gives every device to one model server. MIG slices, compute modes and shared memory vary by hardware; CUDA toolkit/library ABI errors often appear only at runtime.

When to reach for it

  • The fit is strongest for this job: expose GPUs to containers with the NVIDIA Container Toolkit and --gpus flags. Pair it with nvidia-smi inside and outside the container, run a matrix multiply, then verify memory/device visibility and scheduler contention in the runbook.
  • Production NVIDIA Toolkit changes should make --gpus observable through nvidia-ctk runtime configure --runtime=docker; docker run --rm --gpus "device=0,capabilities=compute,utility" nvidia/cuda:12.6.3-base nvidia-smi, rather than trusting the runtime default.
  • Keep a rollback example for the case where installing an NVIDIA driver inside the image or allocating all GPU memory to one process in a shared node.

When to avoid or be careful

  • Do not accept command success while the system can still fail by installing an NVIDIA driver inside the image or allocating all GPU memory to one process in a shared node.
  • Avoid erasing CUDA protection merely to dodge this cost: “Device-specific allocation maximizes isolation; all-GPU access is simple but prevents concurrent placement and capacity accounting”.
  • Do not replace the evidence path-nvidia-smi inside and outside the container, run a matrix multiply, then verify memory/device visibility and scheduler contention-with a screenshot or a mutable tag.

nvidia-ctk runtime configure --runtime=docker; docker run --rm --gpus "device=0,capabilities=compute,utility" nvidia/cuda:12.6.3-base nvidia-smi: practical choices

Explicit NVIDIA Toolkit
Best for: Expose GPUs to containers with the NVIDIA Container Toolkit and --gpus flags, with a reviewed runbook.

Strengths: NVIDIA Container Toolkit configures the OCI runtime to expose host GPU devices, driver libraries and cgroup/namespace support. --gpus controls requested devices and capabilities; an image must match the host driver/compute compatibility without attempting to ship a Linux kernel driver.

Watch out: Device-specific allocation maximizes isolation; all-GPU access is simple but prevents concurrent placement and capacity accounting.

Ambient default
Best for: Short-lived --gpus experiments with low blast radius.

Strengths: It can begin with nvidia-ctk runtime configure --runtime=docker; docker run --rm --gpus "device=0,capabilities=compute,utility" nvidia/cuda:12.6.3-base nvidia-smi and fewer surrounding controls.

Watch out: It silently accepts installing an NVIDIA driver inside the image or allocating all GPU memory to one process in a shared node, which makes the result hard to reproduce after promotion.

Managed CUDA
Best for: Teams that centralize CUDA policy across many workloads.

Strengths: A CPU-only CI host cannot validate GPU behavior, and --gpus all gives every device to one model server. MIG slices, compute modes and shared memory vary by hardware; CUDA toolkit/library ABI errors often appear only at runtime.

Watch out: The platform adds an ownership and debugging layer; retain nvidia-smi inside and outside the container, run a matrix multiply, then verify memory/device visibility and scheduler contention as the direct check.

Interview signals & numbers to know

When this topic comes up

  • nvidia-ctk runtime configure --runtime=docker; docker run --rm --gpus "device=0,capabilities=compute,utility" nvidia/cuda:12.6.3-base nvidia-smi
  • nvidia-smi inside and outside the container, run a matrix multiply, then verify memory/device visibility and scheduler contention
  • Failure signature: installing an NVIDIA driver inside the image or allocating all GPU memory to one process in a shared node
  • Trade-off: Device-specific allocation maximizes isolation; all-GPU access is simple but prevents concurrent placement and capacity accounting.

Benchmarks & rules of thumb

1 device index -
device=0 in the example
2 capabilities -
compute and utility requested
0 kernel drivers -
should be owned by an ordinary container image

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful nvidia-ctk runtime configure --runtime=docker; docker run --rm --gpus "device=0,capabilities=compute,utility" nvidia/cuda:12.6.3-base nvidia-smi as proof and skipping nvidia-smi inside and outside the container, run a matrix multiply, then verify memory/device visibility and scheduler contention.
  • Installing an NVIDIA driver inside the image or allocating all GPU memory to one process in a shared node
  • Optimizing NVIDIA Toolkit without accepting that device-specific allocation maximizes isolation; all-GPU access is simple but prevents concurrent placement and capacity accounting.

Likely interviewer follow-ups

  • Why does nvidia-ctk runtime configure --runtime=docker; docker run --rm --gpus "device=0,capabilities=compute,utility" nvidia/cuda:12.6.3-base nvidia-smi address NVIDIA Toolkit here rather than through application code?
  • How would you distinguish healthy --gpus from the failure “installing an NVIDIA driver inside the image or allocating all GPU memory to one process in a shared node” using nvidia-smi inside and outside the container, run a matrix multiply, then verify memory/device visibility and scheduler contention?
  • When would this trade-off-“Device-specific allocation maximizes isolation; all-GPU access is simple but prevents concurrent placement and capacity accounting”-justify a different CUDA design?
Interview tip: Give one concrete operation-nvidia-ctk runtime configure --runtime=docker; docker run --rm --gpus "device=0,capabilities=compute,utility" nvidia/cuda:12.6.3-base nvidia-smi-and one proof-nvidia-smi inside and outside the container, run a matrix multiply, then verify memory/device visibility and scheduler contention. Then name the boundary: installing an NVIDIA driver inside the image or allocating all GPU memory to one process in a shared node.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply GPU Acceleration in Docker (NVIDIA Container Toolkit & --gpus all) with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Configuring the Docker Daemon (daemon.json) for Production
Next topic
Running Docker on Cloud VMs (AWS EC2, DigitalOcean, Hetzner)