安装
1.Set up Docker's Apt repository.
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
2.Install the Docker packages.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
3.Verify that the Docker Engine installation is successful by running the hello-world image.
sudo docker run hello-world
卸载
1.Uninstall the Docker Engine, CLI, containerd, and Docker Compose packages:
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
2.Images, containers, volumes, or custom configuration files on your host aren't automatically removed. To delete all images, containers, and volumes:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
后续步骤
1.Create the docker group.
sudo groupadd docker
2.Add your user to the docker group.
sudo usermod -aG docker $USER
3.You can run the following command to activate the changes to groups(激活用户组):
newgrp docker
4.Verify that you can run docker commands without sudo.
docker run hello-world
5.配置阿里镜像加速:
sudo service docker stop
sudo mkdir -p /etc/docker
sudo vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://gyd30bw2.mirror.aliyuncs.com"],
"bip": "172.0.0.1/24"
}
Tips: bip:设置docker的ip,防止与本机ip冲突,避免ip访问服务异常
6.docker参数配置重新加载+重启
sudo systemctl daemon-reload
sudo systemctl restart docker
7.Access an NVIDIA GPU
确保已经安装了显卡驱动,查看本机显卡驱动信息执行如下:
nvidia-smi
![](https://img.haomeiwen.com/i14750869/6f919ba0543076b7.png)
安装nvidia-container-runtime:
sudo apt-get install nvidia-container-runtime
确保可以查询到nvidia-container-runtime-hook
which nvidia-container-runtime-hook
调用GPU创建容器:
docker run -it --rm --gpus '"device=0,2"' ubuntu nvidia-smi
效果如下:
![](https://img.haomeiwen.com/i14750869/6f919ba0543076b7.png)
8.查看容器映射路径:
docker inspect dockertest | grep Mounts -A 20
网友评论