How do you pass GPUs to containers?
AdvancedProductionResource Limits, Health & Reliability
Answer
Install the NVIDIA driver and NVIDIA Container Toolkit, configure the runtime (nvidia-ctk runtime configure --runtime=docker), then:
docker run --rm --gpus all nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smi
docker run --gpus '"device=0,1"' ...
Compose uses deploy.resources.reservations.devices with driver: nvidia. The CUDA image version must be compatible with the host driver.
More on Resource Limits, Health & Reliability
How do you set memory and CPU limits, and what happens when they are exceeded?BeginnerWhat is the difference between `--cpus`, `--cpu-shares` and `--cpuset-cpus`?BeginnerWhat does `--memory-reservation` do?AdvancedHow do you diagnose an OOM-killed container?IntermediateWhy do JVM and Node services in containers need explicit memory flags?IntermediateWhat is CPU throttling, and how do you detect it?Advanced