- Notice
- Summarized environments about the Docker with the Nvidia Container Toolkit
- How to install the docker
- How to install the Nvidia Container Toolkit
- Docker image
- Docker container
- Reference
- A guide for Docker with the Nvidia Container Toolkit (i.e. Nvidia-Docker 2.0)
- I recommend that you should ignore the commented instructions with an octothorpe, #.
- Modified date: Dec. 22, 2020.
- Operating System (OS): Ubuntu MATE 18.04.3 LTS (Bionic)
- Graphics Processing Unit (GPU): NVIDIA TITAN Xp, 1ea
- GPU driver: Nvidia-440.100
- CUDA toolkit: CUDA 10.2
- cuDNN: cuDNN v7.6.5
- Docker: Docker version 20.10.1, build 831ebea
- Docker image: nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
-
Docker installation.
usrname@hostname:~/curr_path$ curl https://get.docker.com | sh usrname@hostname:~/curr_path$ sudo systemctl start docker && sudo systemctl enable docker
-
Check the docker version.
usrname@hostname:~/curr_path$ sudo docker --version
Docker version 20.10.1, build 831ebea
-
Setup the repository and the Gnu Privacy Guard (GPU) key.
usrname@hostname:~/curr_path$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) usrname@hostname:~/curr_path$ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - usrname@hostname:~/curr_path$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list usrname@hostname:~/curr_path$ sudo apt-get update
-
Install the Nvidia-Docker 2.0 for the Nvidia Container Toolkit.
usrname@hostname:~/curr_path$ sudo apt-get install -y nvidia-docker2 usrname@hostname:~/curr_path$ sudo systemctl restart docker
-
Test the Nviida-Docker 2.0.
usrname@hostname:~/curr_path$ sudo docker run --rm --gpus all nvidia/cuda:10.2-base nvidia-smi
Tue Dec 22 08:40:19 2020 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 440.100 Driver Version: 440.100 CUDA Version: 10.2 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 TITAN Xp Off | 00000000:01:00.0 On | N/A | | 23% 30C P8 10W / 250W | 518MiB / 12192MiB | 0% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| +-----------------------------------------------------------------------------+
-
List docker images.
usrname@hostname:~/curr_path$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE nvidia/cuda 10.2-base fbd4a873bb90 7 days ago 107MB
-
Pull a docker image.
- Target image: nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
usrname@hostname:~/curr_path$ sudo docker pull nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
- Target image: nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
-
Remove a docker image.
- Target image tag: nvidia/cuda:10.2-base
- Target image ID: fbd4a873bb90
usrname@hostname:~/curr_path$ sudo docker rmi fbd4a873bb90
-
Remove a docker image with the corresponding docker container.
- Target image tag: nvidia/cuda:10.2-base
- Target image ID: fbd4a873bb90
usrname@hostname:~/curr_path$ sudo docker rmi -f fbd4a873bb90
-
Run a docker container.
- There are two options for command: i) image tag, ii) image ID.
- Target image tag: nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
- Target image ID: a4bdb1190443
# i) image tag usrname@hostname:~/curr_path$ sudo docker run -it nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04 /bin/bash
# ii) iamge ID usrname@hostname:~/curr_path$ sudo docker run -it fbd4a873bb90 /bin/bash
-
List docker containers.
- List working docker containers
- There are two options for result: i) image tag, ii) image ID.
usrname@hostname:~/curr_path$ sudo docker ps
# i) image tag CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2170c31af220 nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04 "/bin/bash" 3 minutes ago Up 3 minutes vigilant_feynman
# ii) image ID CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f7912486a8dc fbd4a873bb90 "/bin/bash" 5 minutes ago Up 5 minutes distracted_buck
- There are two options for result: i) image tag, ii) image ID.
- List all docker containers
- Please note that the results are not been shown.
- There are two options for result: i) image tag, ii) image ID.
usrname@hostname:~/curr_path$ sudo docker ps --all
- List working docker containers
-
Pause and unpause a docker container.
- Target container ID: f7912486a8dc
- Pause
usrname@hostname:~/curr_path$ sudo docker pause f7912486a8dc
- Unpause
usrname@hostname:~/curr_path$ sudo docker unpause f7912486a8dc
-
Stop a docker container.
- Target container ID: f7912486a8dc
usrname@hostname:~/curr_path$ sudo docker stop f7912486a8dc
- Target container ID: f7912486a8dc
-
Start the stopped docker container.
- Get the stopped docker container ID.
usrname@hostname:~/curr_path$ sudo docker ps -all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f7912486a8dc fbd4a873bb90 "/bin/bash" 23 minutes ago Exited (127) 2 minutes ago distracted_buck
- Target container ID: f7912486a8dc
usrname@hostname:~/curr_path$ sudo docker start f7912486a8dc
- Check whether the docker container is started.
usrname@hostname:~/curr_path$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f7912486a8dc fbd4a873bb90 "/bin/bash" 27 minutes ago Up 2 seconds distracted_buck
- Get the stopped docker container ID.
-
Restart the docker container.
- Please note that the results are not been shown.
- Target container ID: f7912486a8dc
usrname@hostname:~/curr_path$ sudo docker restart f7912486a8dc
-
Attach a working docker container.
- Target container ID: f7912486a8dc
usrname@hostname:~/curr_path$ sudo docker attach f7912486a8dc
root@f7912486a8dc:/#
- Target container ID: f7912486a8dc
-
Remove a docker container.
- Please note that the docker container should be stopped before removing it.
- Target container ID: f7912486a8dc
usrname@hostname:~/curr_path$ sudo docker rm fbd4a873bb90
- Check whether the docker container is removed.
usrname@hostname:~/curr_path$ sudo docker start
Error response from daemon: No such container: f7912486a8dc Error: failed to start containers: f7912486a8dc
-
Remove all docker containers.
- Please note that the docker containers should be stopped before removing them.
sudo docker rm `sudo docker ps -a -q`
- Check whether the docker containers are removed.
usrname@hostname:~/curr_path$ sudo docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- Please note that the docker containers should be stopped before removing them.