Foreword¶
Since the official Docker website is inaccessible, this guide provides an installation method using the Alibaba Cloud mirror and also supports NVIDIA GPU integration.
Install Docker¶
1. Pre-installation Preparation¶
# Install necessary system tools
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# Add the GPG key:
install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Create the repository source list
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
2. Install Docker¶
# Update the apt source again
sudo apt update
# Install Docker CE
sudo apt install -y docker-ce
# Verify Docker version availability
sudo apt-cache madison docker-ce
To configure Docker with domestic image sources:
- Open the Docker configuration file
/etc/docker/daemon.json:
sudo vim /etc/docker/daemon.json
- Add the following content to the file:
{
"registry-mirrors": ["https://ccr.ccs.tencentyun.com"]
}
If using multiple mirrors, add additional URLs in the registry-mirrors array separated by commas.
- Save the configuration file and restart the Docker service to apply changes:
sudo systemctl restart docker
Test:
# Verify Docker installation
sudo docker run hello-world
Expected output:
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
Support NVIDIA GPU¶
To enable Docker to use GPUs, install the nvidia-container-toolkit. First, ensure you have an NVIDIA graphics card and the appropriate driver installed.
# Configure the production repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
# Update package lists
sudo apt-get update
# Install the nvidia-container-toolkit package
sudo apt-get install -y nvidia-container-toolkit
# Configure Docker runtime
sudo nvidia-ctk runtime configure --runtime=docker
# After setting the default runtime, restart the Docker daemon to complete installation
sudo systemctl restart docker
# Test GPU access
sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi
After successful execution, the GPU information should be displayed in the output.