Using detkit on Docker#

Install Docker#

The followings are instructions to install docker on Linux. To install on other operating systems, see Install Docker Engine from Docker documentation.

Install docker by

sudo apt update
sudo apt install ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
    sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
    https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
sudo systemctl start docker
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
sudo systemctl start docker

Configure docker to run docker without sudo password by

sudo groupadd docker
sudo usermod -aG docker $USER

Then, log out and log back. If docker is installed on a virtual machine, restart the virtual machine for changes to take effect.

Get detkit Docker Image#

docker-size

Get the detkit docker image by

docker pull sameli/detkit

The docker image has the following pre-installed:

  • CUDA: in /usr/local/cuda

  • Python 3.9: in /usr/bin/python3

  • Python interpreters: ipython, jupyter

  • Editor: vim

Examples of Using detkit Docker Container#

The followings are some examples of using docker run with various options:

  • To check the host’s NVIDIA driver version, CUDA runtime library version, and list of available GPU devices, run nvida-smi command by:

    docker run sameli/detkit nvidia-smi
    
  • To run the container and open Python interpreter directly at startup:

    docker run -it sameli/detkit
    

    This also imports detkit package automatically.

  • To run the container and open IPython interpreter directly at startup:

    docker run -it sameli/detkit ipython
    

    This also imports detkit package automatically.

  • To open Bash shell only:

    docker run -it --entrypoint /bin/bash sameli/detkit
    
  • To mount a host’s directory, such as /home/user/project, onto a directory of the docker’s container, such as /root, use:

    docker run -it -v /home/user/project:/root sameli/detkit
    

Deploy detkit Docker Container on GPU#

To access the host’s GPU device from inside the docker container, you should install NVIDIA Container Toolkit.

Install NVIDIA Container Toolkit#

Install NVIDIA Container Toolkit as follows.

Add the package to the repository:

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 https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo yum-config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

Install nvidia-contaner-toolkit by:

sudo apt update
sudo apt install -y nvidia-container-toolkit
sudo yum install -y https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.4.3-3.1.el7.x86_64.rpm
sudo dnf install -y https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.4.3-3.1.el7.x86_64.rpm

Restart docker:

sudo systemctl restart docker

Run detkit Docker Container on GPU#

To use the host’s GPU from the docker container, simply add --gpus all to any of the docker run commands described earlier, such as by

docker run --gpus all -it sameli/detkit