Prompt
How do I fix CUDA version conflicts across containers?
Latest observation
CUDA version conflicts across containers usually come from mixing up three different version layers:
- Host NVIDIA driver
- Container CUDA runtime / toolkit
- Your app/framework CUDA dependencies
(PyTorch, TensorFlow, cuDNN, NCCL, etc.)
The key rule is:
The host driver must be new enough for the CUDA runtime inside the container.
Usually, the container does not need the full CUDA driver, only the user-space libraries.
Common fixes
1) Match the container CUDA version to the host driver
Check:
- Host driver:
nvidia-smi - Container CUDA runtime:
or inspect the image tags, likenvcc --versionnvidia/cuda:12.4.1-runtime-ubuntu22.04
If the container uses CUDA 12.x but the host driver only supports CUDA 11.x, you’ll get conflicts.
Fix: use a container image with a CUDA version supported by the host driver, or upgrade the host driver.
2) Use NVIDIA container runtime properly
Make sure containers are launched with GPU passthrough:
docker run --gpus all ...
And ensure the NVIDIA Container Toolkit is installed on the host.
If you are manually mounting /usr/local/cuda or driver libraries from the host, that can cause conflicts.
Avoid bind-mounting host CUDA libraries into the container unless you really know why.
3) Don’t mix multiple CUDA installations inside one container
Inside a container, having:
/usr/local/cuda-11.8/usr/local/cuda-12.1/usr/lib/x86_64-linux-gnu/
can confuse LD_LIBRARY_PATH and app loaders.
Fix:
Pick one CUDA toolkit version per image, and ensure:
PATHpoints to the rightbinLD_LIBRARY_PATHpoints to the rightlib64
Example:
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
4) Align framework wheels with CUDA version
PyTorch/TensorFlow packages are often built for specific CUDA versions.
Examples:
- PyTorch wheels may be built for
cu118,cu121, etc. - TensorFlow packages may expect specific CUDA/cuDNN combinations.
If the framework was built for CUDA 11.8 but your container has CUDA 12.2, you may see runtime errors.
Fix: install the framework build matching the container CUDA version, or use vendor images that already match.
Examples:
- PyTorch official images
- NVIDIA NGC images
- TensorFlow GPU images
5) Use a base image that already matches your stack
Instead of building everything from scratch, use a known-good base:
FROM nvidia/cuda:12.4.1-cudnn-runtime-ubuntu22.04
Then install only the app dependencies.
This reduces the chance of library mismatch.
6) Check for conflicting library paths
Inside the container, inspect:
echo $LD_LIBRARY_PATH
ldconfig -p | grep cuda
which nvcc
Conflicts often come from:
/usr/local/cuda/lib64vs system libs- Conda environments shipping their own CUDA libs
- pip-installed packages bundling CUDA-dependent binaries
Fix: remove or reorder conflicting paths.
7) In Kubernetes / multi-container setups, keep images consistent
If multiple containers in the same pod/job use different CUDA versions, they can conflict indirectly if they share:
- a mounted volume
- host-installed CUDA libs
- the same runtime assumptions
Fix: standardize on the same CUDA major/minor version across all GPU containers in the workload.
Quick troubleshooting checklist
Run these inside the container:
nvidia-smi
nvcc --version
python -c "import torch; print(torch.version.cuda)"
python -c "import tensorflow as tf; print(tf.sysconfig.get_build_info())"
echo $LD_LIBRARY_PATH
Then verify:
- Host driver supports container CUDA
- Framework CUDA version matches container
- No extra CUDA libs are being injected from host or conda
Best practices to prevent conflicts
- Use NVIDIA Container Toolkit
- Use official CUDA base images
- Keep one CUDA version per image
- Match framework wheels to that CUDA version
- Avoid host library bind mounts
- Document a supported matrix:
- host driver version
- container CUDA version
- framework version
- cuDNN version
If you want the shortest answer:
Make sure the host NVIDIA driver is compatible with the container’s CUDA version, and don’t mix multiple CUDA libraries inside the container. Use a single known-good base image and install framework builds that match that CUDA version.
If you tell me:
- your host driver version
- container image tag
- framework (PyTorch/TensorFlow/etc.)
- the exact error message
…I can help pinpoint the conflict.