This repository provides a Docker environment for deep learning based on Ubuntu 22.04, integrating CUDA 12.6.0, PyTorch, and TensorFlow. It helps you avoid tedious environment configuration and dependency issues.
This Docker image contains the following main components:
- Base Image: nvidia/cuda:12.6.0-cudnn-runtime-ubuntu22.04
- Python: 3.10
- Deep Learning Frameworks:
- PyTorch (latest version with CUDA support)
- TensorFlow 2.15.0
- Common Scientific Computing Libraries:
- NumPy
- SciPy
- Pandas
- Scikit-learn
- Matplotlib
- And other data processing tools
- Docker with NVIDIA Docker support installed
- NVIDIA drivers installed
Important Note: Ensure your NVIDIA driver supports CUDA 12.6.0 or higher. If your host NVIDIA driver version is incompatible, you will encounter the following error:
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error running hook #0: error running hook: exit status 1, stdout: , stderr: Auto-detected mode as 'legacy' nvidia-container-cli: requirement error: unsatisfied condition: cuda>=12.6, please update your driver to a newer version, or use an earlier cuda container: unknown.
Solutions:
- Update your NVIDIA driver to a version that supports CUDA 12.6
- Or modify the base image in the Dockerfile to use a CUDA version compatible with your driver
You can build the image using the provided Dockerfile:
docker build -t ubuntu2204_dl:latest -f Dockerfile_Ubuntu22_DeepL.txt .
# Container with GPU support
docker run --gpus all -it --rm ubuntu2204_dl:latest bash
# Mount local directory to container
docker run --gpus all -it --rm -v /your/local/path:/workspace ubuntu2204_dl:latest bash
You can create a custom deep learning environment based on this Dockerfile:
-
Copy and modify the Dockerfile:
cp Dockerfile_Ubuntu22_DeepL.txt Dockerfile_Custom.txt
-
Edit Dockerfile_Custom.txt to meet your needs, for example, to add more libraries:
# Add at the appropriate location in the Dockerfile RUN $PIP_INSTALL \ transformers \ opencv-python \ pillow \ jupyter
-
Build your custom image:
docker build -t my_custom_dl:v1 -f Dockerfile_Custom.txt .
-
Save and share your image:
# Save the image as a tar file docker save -o my_custom_dl_image.tar my_custom_dl:v1 # Load the image on another machine docker load -i my_custom_dl_image.tar
There are several common ways to mount local directories to a Docker container:
-
Basic mount (recommended for development):
docker run --gpus all -it --rm -v /host/path:/container/path ubuntu2204_dl:latest bash
-
Read-only mount (for data security):
docker run --gpus all -it --rm -v /host/path:/container/path:ro ubuntu2204_dl:latest bash
-
Mounting multiple directories:
docker run --gpus all -it --rm \ -v /host/code:/workspace \ -v /host/data:/data \ -v /host/output:/output \ ubuntu2204_dl:latest bash
-
Using data volumes (for data persistence):
# Create a named volume docker volume create dl_data # Use the volume docker run --gpus all -it --rm -v dl_data:/data ubuntu2204_dl:latest bash
-
Mounting with specific user permissions (resolving permission issues):
docker run --gpus all -it --rm \ -v /host/path:/container/path \ --user $(id -u):$(id -g) \ ubuntu2204_dl:latest bash
Due to network limitations, pulling Docker images in mainland China may be slow. You can use the following Docker image acceleration services to improve download speed.
On Linux systems, edit or create the /etc/docker/daemon.json
file:
sudo mkdir -p /etc/docker
sudo vim /etc/docker/daemon.json
Copy the following content to the file:
{
"registry-mirrors": [
"https://docker.1ms.run",
"https://docker.xuanyuan.me"
],
"runtimes": {
"nvidia": {
"args": [],
"path": "nvidia-container-runtime"
}
}
}
Restart the Docker service to apply the configuration:
sudo systemctl daemon-reload
sudo systemctl restart docker
Run the following commands inside the container to verify the environment is correctly installed:
# Verify PyTorch and CUDA
python -c "import torch; print('PyTorch version:', torch.__version__); print('CUDA available:', torch.cuda.is_available())"
# Verify TensorFlow and GPU support
python -c "import tensorflow as tf; print('TensorFlow version:', tf.__version__); print('GPU devices:', tf.config.list_physical_devices('GPU'))"
You can add more libraries and tools by modifying the Dockerfile, for example:
# Add at the appropriate location in the Dockerfile
RUN $PIP_INSTALL \
transformers \
opencv-python \
pillow \
jupyter
Ensure your system has correctly installed NVIDIA drivers and the NVIDIA Container Toolkit:
# Install NVIDIA Container Toolkit
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
You can use the following command to check which CUDA version your NVIDIA driver supports:
nvidia-smi
The output will show "CUDA Version" - make sure it's compatible with the CUDA version in your Docker image.
For more detailed information, please refer to the following resources:
- Docker/DockerHub Mirrors in China: For a comprehensive list of Docker registry mirrors available in China, visit: https://cloud.tencent.com/developer/article/2485043
- Dockerfile References: This project was inspired by the deepo project. For more Dockerfile examples and best practices, check: https://github.com/ufoym/deepo/tree/master/docker
- NVIDIA Driver, CUDA, and cuDNN Compatibility: For detailed information about kernel version, NVIDIA driver, CUDA, and cuDNN compatibility and installation guides, refer to: https://blog.csdn.net/qq_23076153/article/details/112754824
- PyTorch Environment Installation: For version compatibility between PyTorch, torchvision, and Python, as well as environment installation guides, visit: https://blog.csdn.net/trr27/article/details/144162171
This project is licensed under the MIT License. See the LICENSE file for details.