Friday, February 15, 2019

HOWTO : Install docker-ce and nvidia-docker2 on Ubuntu 18.04.2 and Kali Linux 2019.1

docker-ce requires nvidia-docker2 on CUDA system.

Install nVidia driver :

On Ubuntu 18.04.2 :
HOWTO : Intel and nVidia GPUs on Ubuntu 18.04.1 LTS

On Kali Linux 2019.1 :
HOWTO : nVidia and HashCat on Kali Linux 2018.4

Uninstall docker.io (if any)

sudo apt remove docker docker-engine docker.io containerd runc docker-compose

Ready for docker-ce

On Ubuntu 18.04.2 :

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


On Kali Linux 2019.1 :

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

echo "deb [arch=amd64] https://download.docker.com/linux/debian stretch stable" > /etc/apt/sources.list.d/docker-ce.list

apt update


Ready for nvidia-docker2

On Ubuntu 18.04.2 :

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 update


On Kali Linux 2019.1 :

curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -

curl -s -L https://nvidia.github.io/nvidia-docker/debian9/nvidia-docker.list | tee /etc/apt/sources.list.d/nvidia-docker.list

apt update


Install docker-ce and nvidia-docker2

apt-cache madison docker-ce
apt-cache madison nvidia-docker2


Find the most matched versions and the following settings are for my system at the time of this writing :

On Ubuntu 18.04.2 :

sudo apt install docker-ce=18.03.1-ce-0-debian docker-ce-cli=18.03.1-ce-0-debian containerd.io nvidia-docker2=2.0.3+docker18.03.1-1 nvidia-container-runtime=2.0.3+docker18.03.1-1

On Kali Linux 2019.1 :

apt install docker-ce=18.03.1-ce-0-debian docker-ce-cli=18.03.1-ce-0-debian containerd.io nvidia-docker2=2.0.3+docker18.03.1-1 nvidia-container-runtime=2.0.3+docker18.03.1-1

If the versions are not matched, the installation will be failed.

Install docker-compose

sudo apt install python3-pip
pip3 install docker-compose pip --ugrade


Configure docker-ce

sudo nano /etc/docker/daemon.json

Add the following in front of "runtimes": { :

"default-runtime": "nvidia",

sudo systemctl enable docker
sudo systemctl start docker


Basic usage

docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi

Remark

Make sure the nvidia driver and CUDA versions in the host computer is equal or greater than the versions in docker containers. Otherwise, docker containers refuse to start.

That's all! See you.