Skip to main content

Docker installation

Environment

In this tutorial, the OS is on Ubuntu 20.04

Install docker in Ubuntu 20.04

Reference : https://www.gushiciku.cn/pl/pRNY/zh-tw

sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

sudo systemctl status docker

sudo usermod -aG docker $USER
sudo chmod 777 /var/run/docker.sock

Install the NVIDIA-container package to enable GPU in docker

You can check the page from here.

For Debian-based distributions:

curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
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

Install nvidia-container-toolkit:

sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker

Please dont forget to restart docker!

Daemon.json file

$ cat /etc/docker/daemon.json

{
"runtimes": {
"nvidia": {
"path": "nvidia-container-runtime",
"runtimeArgs": []
}
},
"graph": "/home/user/472GB/Docker",
"storage-driver": "overlay2",
"insecure-registries":["ip:5568"]
}
  • graph : the place where you want to store
  • insecure-registries : if you have a self-managed docker image registery, you can add this key; otherwise, you can remove it.

Important

測試如果是 19.03版本儲存的位置key是graph 但是測試 23.0.06版本儲存的位置key改為 data-root

{
"data-root": "/home/chieh/472GB/Docker"
}

Install docker-compose

Old version 1.29.2

sudo curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

New version v2.23.1

sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Reference: compose-install