Docker Installation and Create Environment
Published:
Docker Installation
Step 1: Install The Docker
Refer to DockerHub
- Add Soucre
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
- Install Docker
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 2: Install The Nvidia Docker Toolkits
Refer to this Blog
- Add the package repositories
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 -O https://nvidia.github.io/nvidia-docker/gpgkey #大写欧,会在本地保存一个gpgkey文件
sudo apt-key add gpgkey#会输出OK
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
- Install Toolkit
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
Examples: Create a Docker Container
- Pull a Pytorch Images from the DockerHub/Pytorch
For example:
sudo docker pull pytorch/pytorch:1.12.0-cuda11.3-cudnn8-devel
use sudo docker images
to check the existing images
The create contains with all gpus and the data volume with multi-processing and swap:
sudo docker run --gpus all -it --memory-swap=-1 --shm-size 16g -v /home/zliu:/home -v /media/zliu/data11/dataset:/data pytorch/pytorch:2.0.1-cuda11.7-cudnn8-devel