Adding a Docker container icon to your Unity launcher (Ubuntu 15.04)

If there’s a Docker container you run a lot it’s nice to be able to single-click an icon on the desktop to run it. This is particularly useful if the container has an interactive shell.

Here’s how to do that for the Unity desktop (Ubuntu 15.04), using the Azure-CLI container as an example. Using this I can click on the desktop any time I want to start a new Azure CLI container. I can type exit in the container to shut it down, or just close the terminal window if I want to attach to it later.

The basic steps are:

  1. Make sure Docker is installed. See http://docs.docker.com/installation/ubuntulinux/
  2. Create a docker group and add yourself to it so you don’t have to sudo each time you want to run docker:
    groupadd dockersudo 
    usermod -g docker myuserid

    Reboot, or at least restart the desktop so when you start a terminal in Unity and run “groups” it says you’re in the docker group.

  3. Create a script to run your docker container. In my case it looks like this:
    #!/bin/bash
    docker run -it microsoft/azure-cli

    Make sure the script is executable:

    sudo chmod a+x /opt/azure-cli.sh
  4. Save the script somewhere e.g.: /opt/azure-cli.sh
  5. Copy the image you want to use as an icon to /usr/share/icons. E.g. find a small image you want to use on the web and Save-As from your browser to this directory.
  6. Create a desktop file for your container app, and make the “Icon” entry point to your image, and the “Exec” entry point to your script. E.g. for the Azure-CLI container:
    sudo vi /usr/share/applications/azure-cli.desktop
    
    [Desktop Entry]
    Name=Azure-CLI
    Comment=
    Exec=/opt/azure-cli.sh
    Icon=/usr/share/icons/azure.png
    Terminal=true
    Type=Application
    StartupNotify=true
  7.  Go to /usr/share/applications in the file manager and drag your icon for your container app into the launcher bar. You can go there directly with this command:
    nautilus /usr/share/applications &

Now you should see the new icon in the launcher:
Launcher bar

When you run the container, in the case of Azure-CLI you’ll be in the interactive shell. E.g. after launching and typing “azure login”:

container

Acknowledgements:
The following article on adding Minecraft to the Unity launcher was very helpful in figuring out how to do this for Docker containers:
http://askubuntu.com/questions/34408/how-to-add-minecraft-to-the-unity-launcher

Advertisements
This entry was posted in Containers, Ubuntu and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s