- Newest
- Most votes
- Most comments
You need to install and configure NVIDIA Container Toolkit in order for docker to use NVIDIA GPU. You can refer to this article for installation and configuration instructions.
I would suggest you consider using AWS Deep Learning AMI (DLAMI) which are available at no additional charge and comes with NVIDIA driver, Python, NVIDIA Container toolkit pre-installed. You can try AWS Deep Learning OSS AMI GPU PyTorch 2.7 (Ubuntu 22.04).
For guidance using DLAMI and installing graphical desktop, you can refer to Deep Learning graphical desktop on Ubuntu Linux with AWS Deep Learning AMI (DLAMI).
Based on your description, you're experiencing a CUDA driver initialization issue in your Docker container despite having a properly configured host system. Here are several potential solutions to resolve this issue:
- NVIDIA Container Toolkit Configuration: Make sure the NVIDIA Container Toolkit is properly installed and configured on your host system. You should run:
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
This ensures Docker is properly configured to work with NVIDIA GPUs.
- Environment Variables: While you've included some environment variables in your Dockerfile, try adding these when running your container:
-e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=all
-
CUDA Version Compatibility: There might be a version mismatch between your host CUDA (12.4) and the container. Try using a PyTorch image that matches your host CUDA version more closely.
-
Test with NVIDIA CUDA Container: As a diagnostic step, try running an official NVIDIA CUDA container to isolate whether the issue is specific to your custom container:
docker run --gpus all nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smi
If this works, the issue is specific to your container configuration.
- Install numpy: Your error logs show a warning about missing numpy. While this isn't directly related to the CUDA issue, install numpy in your container to eliminate this warning:
pip install numpy
-
Docker Runtime Check: Verify that Docker is using the NVIDIA runtime by checking your Docker daemon configuration.
-
Install CUDA Toolkit in Container: Your Dockerfile has the CUDA base image, but you might need the full CUDA toolkit inside the container. Consider uncommenting the
nvidia-cuda-toolkitline in your Dockerfile.
The fact that PyTorch can access the GPU on the host but not in the container suggests that the container configuration is missing something needed for proper CUDA initialization.
Sources
GPU Instance (g4dn.xlarge) CUDA Driver Initialization Issue in Docker Container | AWS re:Post
GPU on g4dn.xlarge is not active / responding anymore | AWS re:Post
How do I install NVIDIA GPU driver, CUDA Toolkit, NVIDIA Container Toolkit on Amazon EC2 instances running Amazon Linux 2 (AL2)? | AWS re:Post
Install NVIDIA GPU driver, CUDA Toolkit, NVIDIA Container Toolkit on Amazon EC2 instances running Amazon Linux 2 (AL2) | AWS re:Post
Relevant content
asked a year ago
