Installing Docker® and nvidia-docker2

You install Docker® on Red Hat Enterprise Linux™ or Ubuntu® operating systems. You can also install nvidia-docker2 on Ubuntu® operating systems to enable support for GPU devices in the Docker® containers.

Procedure - Red Hat Enterprise Linux™

Complete the following steps to install Docker® on Red Hat Enterprise Linux™. For more details, refer to https://github.com/NVIDIA/nvidia-docker#rhel-docker.

  1. Install Docker®:

    sudo yum install docker
    

    Note: the docker-1.13.1-108.git4ef4b30.el7 package has a known issue with the Nvidia GPUs. Newer versions of Red Hat Enterprise Linux™ Docker work as well. Ensure that the docker-1.13.1-108.git4ef4b30.el7 package is NOT installed.

  2. Reboot the system.

  3. Add the package repositories:

    On IBM® Power®:

    distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
    curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo
    sudo yum install -y nvidia-container-runtime-hook
    sudo systemctl restart docker
    

    On x86:

    distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
    curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo
    sudo yum install -y nvidia-container-toolkit
    sudo systemctl restart docker
    

Procedure - Ubuntu®

Complete the following steps to install Docker® and nvidia-docker2 on Ubuntu®.

  1. For Ubuntu® platforms, a Docker® runtime must be installed. If there is no Docker® runtime installed yet, install Docker®-CE on Ubuntu®.

    On IBM Power:

    sudo apt-get update
    sudo apt-get 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=ppc64el] https://download.docker.com/linux/ubuntu bionic stable"
    sudo apt-get update
    sudo apt-get install docker-ce=18.06.1~ce~3-0~ubuntu
    

    On x86_64:

    sudo apt-get update
    sudo apt-get 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 bionic stable"
    sudo apt-get update
    sudo apt-get install docker-ce
    
  2. Install nvidia-docker2.

    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
    sudo apt-get install nvidia-docker2
    sudo systemctl restart docker.service
    
  3. For each user ID that will run Docker®, add the user ID to the docker group:

    sudo usermod -a -G docker <userid>
    

    Users must log out and log back in to activate this group change.

  4. Verify the setup.

    On IBM Power:

    nvidia-docker run --rm nvidia/cuda-ppc64le:10.2-base-ubuntu18.04 nvidia-smi
    

    On x86_64:

    nvidia-docker run --rm nvidia/cuda:10.2-base-ubuntu18.04 nvidia-smi
    

Notes:

Next steps

After you install Docker®, edit the Docker® daemon configuration file, that is /etc/docker/daemon.json, and make the following updates:

For example, after you make these updates, the daemon configuration file might contain the following configuration:

{
   "runtimes" : {
      "nvidia" : {
         "path" : "/usr/bin/nvidia-container-runtime",
         "runtimeArgs" : []
      }
   },
   "default-runtime" : "nvidia",
   "log-driver": "json-file",
   "log-opts": {
       "max-size": "10m",
       "max-file": "20"
   }
}

After you save your changes, restart the Docker® daemon by running the following command: systemctl docker restart