GPU Acceleration in Docker (NVIDIA Container Toolkit & --gpus all)
Expose GPUs to containers with the NVIDIA Container Toolkit and --gpus flags.
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-smifor 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
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.
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, 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.
Exercise this failure safely: installing an NVIDIA driver inside the image or allocating all GPU memory to one process in a shared node.
How it works, step by step
Step 1 of 41. 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.
- 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 contentionin 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
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.
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.
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-smias proof and skippingnvidia-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-smiaddress 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?
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
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.