Skip to content
StackDecode
AdvancedLesson 25 of 26

Containers with GPUs for ML

Run PyTorch or CUDA workloads in a container.

The host needs the NVIDIA driver and the NVIDIA Container Toolkit. The container carries CUDA libraries, not the driver.

bash
docker run --rm --gpus all nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smi
docker run --rm --gpus all pytorch/pytorch:latest python -c "import torch; print(torch.cuda.is_available())"
docker run --gpus '"device=0"' ...        # a specific GPU

Pin framework and CUDA versions together in your Dockerfile for reproducible training environments, and mount datasets as volumes instead of copying them into the image.