Getting a ROS/Gazebo Docker Instance Up

I am going to document my steps to get a ROS/Gazebo instance running on a (nearly) fresh installation of Xubuntu 16.04 (Xenial). I have decided that I am going to use Docker to do this (or at least investigate using Docker) because it will containerize the environments, which is nice because ROS is extremely invasive (i.e. install a TON of packages), and it will make it easier to pass on/share the work with someone else.

  • I say “nearly” fresh because I had already installed a few things like Chrome, Gitkraken, Git, Tmux, Neovim, and I compiled Julia v0.6… the reason for writing this is that some libs might already have been installed, but I don’t want to go back and start from absolute scratch… if it turns out that this causes problems, then I’ll have to revise.

Installing Docker on Xenial

A couple of notes:

  • Also, I tried installing Docker on Windows, but it wouldn’t work because I only have Windows 10 home edition… it isn’t really a problem though because I am just going to use a dedicated workstation for this… it would be interesting to see if I can instll Docker on teh Windows subsystem for Linux… just looked and found this post that talks about doing it, but it doesn’t sound very easy (basically need to connect to Docker on Windows from WSL)… basically I don’t care about figuring that out right now.
  • I had a question about how Docker is different from a virtual machine this question on stackoverflow explains a bit about it. Basically they are similar, but Docker has a lighter use of system resources… that is grossly over simplifying so read the stackoverflow answer instead.

OK, so why am I using Docker? I found my way to this project that mentioned using Docker, and that piqued my interest. As I read more it seemed like Docker could help me to contain my development environment in a way that others could use it, and more easily reproduce what I did. I am still new to this, so it might not be quite like that, but I think it is a step in the right direction. So, here we go.

  • I am working through this tutorial – this has some intuitive explanations about what containers are.
  • I followed this guide to install Docker from a repository, used the following command to be able to have a consistent version when deploying in different situations
    • This is the command for amd64 builds, the link has other options as well: sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    • followed by: sudo apt-get update
    • finally we get a specific version sudo apt-get install docker-ce=17.06.2~ce-0-ubuntu
    • The docker run hello-world command didn’t work and returned a permission denied error, so I had to add myself to the docker group

Containers for ROS and Gazebo

After poking around on the internet for a while, it finally occurred to me that I should look to see if anyone had ever tried this with ROS/Gazebo. Someone had!! Even better it was someone working at OSRF, and there was an official post on ros.org (also linked below). Anyway, I am going to learn about Docker so I can set up an image of a ROS/Gazebo setup, and then pass it along to whoever else might be working with me.

  • I am going to use this post as a reference for getting the ROS/Gazebo docker, these are available at this link.
    • So, I headed here to pull the ros image docker pull osrf/ros:kinetic-desktop-full-xenial, I could have just did docker pull ros like it says here, but that wouldn’t have guaranteed the version of ROS that I want, which is the version after the :. As a note: docker pull <some package>, automatically pulls the latest tag of the package which can change in time sort of like the master branch of a git repo. Instead, pulling a specific tag will guarantee a consistent version going forward.
    • And for Gazebo here to pull the gazebo image docker pull osrf/gazebo:gzserverX, we’ll see if that is the right one in a little while (again the part after the : is the tag name).
    • The osrf/gazebo image contains several different tags; most of them are different gzweb versions. I have been reading a bit about gzweb, which is basically a version of gzclient that can be accessed through a browser. It still isn’t clear if it has ALL of the capabilities of gzclient. However, both gzclient and gzweb rely on gzserver for the actual data, so maybe they are nearly the same… time will tell.

Viewing the GUI from a container

This is following this basic tutorial. Basically, we need to connect a container to the host’s (the actual computer) X server.

  • I decided to use “The simple way”, by adding the code to open the xhost to the specific container id
docker run -it \
    --env="DISPLAY" \
    --env="QT_X11_NO_MITSHM=1" \
    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    osrf/ros:indigo-desktop-full \
    rqt
export containerId=$(docker ps -l -q)
xhost +local:`docker inspect --format='' $containerId`
docker start $containerId

Letting ROS access Nvidia drivers

I am going to follow this tutorial to do this. I am also using the readme from the Nvidia-docker github repo.

** I am going to leave this alone for now, i’ll come back to this later, I want to get basic functionality up first **

  • I needed to install Nvidia drivers using sudo add-apt-repository ppa:graphics-drivers/ppa, then select the desired driver from the additional drivers part of the settings menu. The driver must be greater than 340.29 according to the install instructions from Nvidia. I chose the latest on the list (this is a ppa with stable drivers) which is 384.90. Then restart the computer.
  • There are also CUDA containers.
  • Now, according to the Nvidia-docker readme run wget -P /tmp https://github.com/NVIDIA/nvidia-docker/releases/download/v1.0.1/nvidia-docker_1.0.1-1_amd64.deb sudo dpkg -i /tmp/nvidia-docker*.deb && rm /tmp/nvidia-docker*.deb
comments powered by Disqus