How-To Setup NVIDIA Docker and NGC Registry on your Workstation – Part 2 Docker and NVIDIA-Docker-v2



This post is where we get moving toward Docker joy. Well, OK, it’s where we get Docker and NVIDIA Docker v2, installed and working in a way that makes sense on a desktop or laptop workstation. The joy part may, or may not, happen for you. That depends on your taste, and whether or not you have suffered the pain of doing your own system administration work building, installing and configuring, possibly research quality, programs (“research quality” is a code phrase for ugly and nearly impossible to install). Of course, you will be trading that pain for the pain of learning and working with docker. My goal is to lessen that pain for you … and for myself!

Notice in the title that is says Part 2. That means there is a Part 1 that you might want to look at. How-To Setup NVIDIA Docker and NGC Registry on your Workstation – Part 1 Introduction and Base System Setup. Also, if you are new to docker and want to read a little about what motivated me to look at it, you can check out, Docker and NVIDIA-docker on your workstation: Motivation. That post and a series of posts after it were written about a year ago. Things have changed since then, enough to warrant doing a refresh. Also, the big motivator for me was using the nicely done collection of docker images in the NGC (NVIDIA GPU Cloud) docker registry. That is where we are headed. Using that docker repository on a “hands-on” machine was liberating. I used it on workstation system when I was testing the Titan V that really made me feel I should go through a detailed setup to help colleagues to take advantage of it. NVIDIA Titan V vs Titan Xp Preliminary Machine Learning and Simulation Tests.


How To Install Docker

The first thing we need to do is to get Docker Community Edition downloaded and installed. You might want to explore the Docker web site but be warned there is a lot of effort there to get you looking at Enterprise Edition. You don’t need that on a workstation! This split between a Community Edition and an Enterprise Edition is one of the changes since I had posted about docker a year ago. Docker Inc. is a commercial organization and provides valuable services, but docker remains open with a vibrant community. What I present below will get docker installed and tested on your workstation.

I am assuming you are doing this on an updated Ubuntu 16.04 system as I detailed in Part1. The following instructions should be robust enough that variations on that wont give you any trouble but, my assumption remains.

Remove old Docker versions

Things have changed so if you are on a system with an old docker install you should clean that up. (It wont hurt anything if you do this on a fresh installed system.) The new Docker is named docker-ce (ce == Community Edition).

sudo apt-get remove docker docker-engine docker.io

Configure the Docker-ce distribution repository

The following packages should already be installed but we’ll check to be sure they are.

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

Next add the GPG signature key for their repo.

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

Docker uses low-level kernel processes so it’s good to check the key to be sure you got the right thing.

sudo apt-key fingerprint 0EBFCD88

The command above will look up the proper key and you can check that it is correct. It output should look like,

pub   4096R/0EBFCD88 2017-02-22
     Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) 
sub   4096R/F273FCD8 2017-02-22

Now add the repository,

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"

I put xenial in the configuration line explicitly rather than relying on the output of lsb_release -cs. (xenial is Ubuntu 16.04)

[Note: I mentioned in Part 1 that I had successfully setup docker on the alpha release of Ubuntu 18.04. When I did that I used this same xenial repository. The most recent repository at this time is Artful 17.10. I looked at the .deb files for the stable releases and they appear to be the same. I don’t recommend that you try 18.04 until it is actually released, but it did work :-)]

Install docker-ce

Now that you have the repository the install is trivial and you will be able to install future updates from this repository too.

sudo apt-get update

sudo apt-get install docker-ce

Add your user name to the docker group

Since this is for your personal workstation you will want to be able to run docker without being root. (Latter we will add more usability with User Name Spaces) The command below will add your username to the docker group. You will need to logout and back in for this to take effect.

sudo usermod -aG docker your-user-name

Test the Docker install

The first obligatory test for a Docker install is to pull and run their default “Hello World” image. If this works then you know that your install is working and that you can pull images from the main Docker registry.

sudo docker run --rm hello-world

That command should pull a very small image from the DockerHub registry, print “Hello World” and a bunch of information about your Docker install.

For a more amusing test you can pull a modified “cowsay + fortune” image that I put in my public DockerHub registry.

docker run --rm dbkdoc/whalefortune

That command should great you with something like, (warning it uses the fortune command and that sometimes outputs “politically incorrect” quotations )

 _________________________________________
/ The problem that we thought was a       \
| problem was, indeed, a problem, but not |
| the problem we thought was the problem. |
|                                         |
\ -- Mike Smith                           /
 -----------------------------------------
   \
    \
     \
                   ##        .
             ## ## ##       ==
          ## ## ## ##      ===
      /""""""""""""""""___/ ===
 ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
      \______ o          __/
       \    \        __/
         \____\______/

How to Install NVIDIA-docker Version 2

Now that you have the latest Docker running on your system you can get NVIDIA Docker installed. With that you will be able to run NVIDIA CUDA, GPU accelerated, docker images.

Note: on the NVIDIA-docker GitHub page it says;

“Warning: This project is based on an alpha release (libnvidia-container). It is already more stable than 1.0 but we need help testing it.”

There you go, do some testing 🙂 I agree that version 2 is more stable than version 1. This is a very good project that is being done well by great people!

Remove any old NVIDIA-docker install and containers

I have been assuming a clean install with a fresh Ubuntu 16.04 and Docker install as I have described above. If you are reading this and you do have an old version 1 NVIDIA-docker you will need to remove it. If you have been using docker or version 1 NVIDIA-docker I recommend doing a little clean-up. The following command should cleanly remove all old NVIDIA-docker cruft.

docker volume rm -f $(docker volume ls -q -f driver=nvidia-docker)

[ note: if there are no volumes that will just return the usage message. That’s OK.]

To clean-up other unused or dangling images,stopped containers (and not other volumes) do,

docker system prune -a

Now completely remove old NVIDIA-docker if you had it installed,

sudo apt-get purge nvidia-docker

Configure the NVIDIA-docker repository

The following command will properly add the GPG repository for you.

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

There are 3 repositories to add for NVIDIA-docker,

deb https://nvidia.github.io/libnvidia-container/ubuntu16.04/amd64
deb https://nvidia.github.io/nvidia-container-runtime/ubuntu16.04/amd64
deb https://nvidia.github.io/nvidia-docker/ubuntu16.04/amd64

This next command will add the repositories neatly together in the /etc/apt/sources.list.d directory for you.

curl -s -L https://nvidia.github.io/nvidia-docker/ubuntu16.04/amd64/nvidia-docker.list | \
    sudo tee /etc/apt/sources.list.d/nvidia-docker.list

Install NVIDIA-docker v2

With those repositories setup the install is simple and you will be able to install future updates too.

sudo apt-get update

sudo apt-get install nvidia-docker2

Another warning on the nvidia-docker2 GitHub page is,

If you have a custom /etc/docker/daemon.json, the nvidia-docker2 package might override it.

If you are doing a fresh install then there shouldn’t be a problem. If you have an existing install and have modified the JSON configuration file /etc/docker/daemon.json then you might want to make a backup of that. [In the next post we will modify that file to add user-name-space support.]

Restart the docker daemon

sudo systemctl restart docker.service

Now you are ready to test.

Test the NVIDIA-docker install

To check that the nvidia-docker2 install is working do the following,

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

If you have used the old nvidia-docker version 1 you will notice that we are using the docker command rather than “nvidia-docker”. This is because the NVIDIA docker is now using libnvidia-container to supply a runtime to docker.

The command above will pull down an NVIDIA built CUDA image from the DockerHub registry, run the nvidia-smi command (system management interface), then exit shutting down and removing the container. You should see information about the NVIDIA driver and hardware on your system. That means you have GPU support in your container. Nice!


I’m going to stop here. Next time we will setup “User Name Spaces” with a configuration that will make using docker on a user workstation environment much better. Right now when you launch a container it is owned by root (like it would be on a server) instead of your user account, we’ll take care of that! After that we will be ready to dig into the juicy NVIDIA NGC docker registry and fire up some of the great machine learning and HPC containers in there.

Happy computing –dbk

Tags: , , ,