Docker and NVIDIA-docker on your workstation: Integration with your Desktop

In this series of posts I’ve been describing how to setup a usable configuration for running Docker containers on your workstation. We are treating containers the same as any other applications so why not integrate them with the desktop the same as other applications! In this post I’ll show you how to add icons, menu items and click-able launchers for your Docker containers.

Here is a list of the previous post for reference,

I am using the Mate desktop on Ubuntu 16.04 for my setup but I am going to describe how to do this setup using standard XDG configuration files. Desktops that follow freedesktop.org standards should be able to use the files we create. (…and that is just about every desktop in existence!)


Directories for configuration files

You should make note of where files for desktop configuration are located.

  • /etc/xdg/ — The system config directory (system .menu files are there)

  • $HOME/.config/ — Your local/personal config directory

  • /usr/share/applications/ — System .desktop files

  • $HOME/.local/applications/ — Your added .desktop files

  • /usr/share/desktop-directories/ — Directory entry .directory files

  • $HOME/.local/desktop-directories/ — You guess it 🙂

I will be making changes only in the $HOME/.local/ and $HOME/.confg/ directories.


Creating .desktop files for “click-able” Docker applications

Lets start by creating a .desktop file for Tensorflow with GPU acceleration. [I’m assuming that you have a Docker and NVIDIA-Docker configuration as I have described in earlier posts.]

The Exec line has the the startup command for the container. That is the most important part! You may want to change that if you don’t like the options I chose.
(The part in quotes can aslo be used directly on the command line.)

.desktop file for Tensorflow

Create a file with the following text in $HOME/.local/share/applications/dockerapps-tensorflow-gpu.desktop

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Tensorflow-GPU
Comment=Tensorflow with GPU acceleration in a Jupyter notebook
Exec=mate-terminal -e 'bash -c "nvidia-docker run --rm -it -p 8899:8888 -v $HOME/projects:/projects tensorflow/tensorflow:latest-gpu" ' --window
Icon=tensorflow.png
Terminal=true

Note 1: [For the Exec statement I used mate-terminal since that is the terminal app I am using on my desktop. You could use gnome-terminal or whatever terminal you are using by default. Also, I called bash -c to run nvidia-docker so that the $HOME shell variable would resolve correctly.]
Note 2: [ I used port 8899 on my host because I often have Jupyter running on it’s default port which is 8888. The Tensorflow container starts up with a message like

Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=74a6d094b3f81ab0a5d1e3f96d73cfddd342

The message refers to the container port 8888. You would need to use port 8899 on your host. (I wish Tensorflow wouldn’t have used such a common port for this!!) ]

Icons

You can put an icon in $HOME/.local/share/icons/tensorflow.png. I used this
Tensorflow icon

If you now check your application menu there should be an entry for your Tensorflow Docker app.

Other menu

Clicking on that should start up Tensorflow in a Jupyter notebook with CUDA GPU acceleration.

With what we did above you could now right click on that menu item and add a desktop or panel link.

Creating a menu folder for Docker containers

Lets go ahead and add a new top-level item for our Docker apps rather than using the generic catch all “Other”.

Check to see if the directories $HOME/.local/share/desktop-directories/ and $HOME/.config/menus exist. If not create them with mkdir.
Then create the file $HOME/.local/share/desktop-directories/dockerapps-DockerApps.directory with the following content,

[Desktop Entry]
Type=Directory
Name=DockerApps
Icon=docker-whale.png

I have added this icon to $HOME/.local/icons/docker-whale.png
docker-whale

Next create the file $HOME/.config/menus/mate-applications.menu with the this XML,



	Applications
	/etc/xdg/menus/mate-applications.menu
        
	  DockerApps
	  dockerapps-DockerApps.directory
	  
	    
	      DockerApps
	    
	  
	


Note: This file is prefixed with “mate” other desktop environment names could be used. [ I may revisit this issue.]

Now we need to add something to the new DockerApps category before it will show on our menus. We will add Category=DockerApps to the end of our .desktop file for Tensorflow. The complete file is now,
$HOME/.local/share/applications/dockerapps-tensorflow-gpu.desktop

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Tensorflow-GPU
Comment=Tensorflow with GPU acceleration in a Jupyter notebook
Exec=mate-terminal -e 'bash -c "nvidia-docker run --rm -it -p 8899:8888 -v $HOME/projects:/projects tensorflow/tensorflow:latest-gpu" ' --window
Icon=tensorflow.png
Terminal=true
Categories=DockerApps

The menu now looks like the following (with the addition of the other .desktop files listed below),
Other menu


More .desktop files

Caffe GPU

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Caffe GPU
Comment=Caffe NVIDA build
Terminal=true
Exec=mate-terminal -e 'bash -c "nvidia-docker run --rm -it -v $HOME/projects:/projects nvidia/caffe:latest" ' --window
Icon=caffe.png
Categories=DockerApps

CentOS 7

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=CentOS 7
Comment=CentOS 7 base
Exec=mate-terminal -e 'bash -c "docker run --rm -it -v $HOME/projects:/projects centos:latest" ' --window
Icon=CentOS-7.png
Terminal=true
Categories=DockerApps

CUDA 8

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=CUDA8
Comment= =NVIDIA CUDA 8
Exec=mate-terminal -e 'bash -c "nvidia-docker run --rm -it -v $HOME/projects:/projects nvidia/cuda:latest" ' --window
Icon=cuda-sm.png
Terminal=true
Categories=DockerApps

NVIDIA DIGITS

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=DIGITS
Comment=NVIDIA DIGITS
Exec=mate-terminal -e 'bash -c "nvidia-docker run --rm -it -p 5000:5000 -v $HOME/projects:/projects nvidia/digits:latest" ' --window
Icon=digits.png
Terminal=true
Categories=DockerApps

CUDA 8 with OpenGL and desktop diaplay

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=CUDA8 OpenGL
Comment CUDA 8 with OpenGL
Exec=mate-terminal -e 'bash -c "nvidia-docker run --rm -it -v $HOME/projects:/projects -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY  dbkdoc/my-cuda8-dev-opengl:latest" ' --window
Icon=cuda-8-opengl.png
Terminal=true
Categories=DockerApps

Ubuntu 16.04

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Ubuntu 1604
Comment=Ubuntu 16.04 base
Exec=mate-terminal -e 'bash -c "docker run --rm -it -v $HOME/projects:/projects ubuntu:16.04" ' --window
Icon=ubuntu1604.png
Terminal=true
Categories=DockerApps

Happy computing! –dbk