Using ROS with Docker in macOS

I am a beginner of both Docker and ROS, thus techinques listed in this article may not be the optimal or even correct ones. Contents will be continuously examined and updated.

ROS Installation in macOS

The latest LTS (long time support) version of ROS Kinetic Kame can be installed on macOS by following the official instructions. Despite a long troubleshooting list, unexpected errors about GUI packages (rqt) and Qt still occurred in my compliation of the recommended Desktop Install. The Bare Bones ROS-Comm installation turned out to be pretty smooth, but I was still obssessed with using graphics in ROS. Docker seemed to be a good choice in this circumstance.

Docker Installation in macOS

Start ROS in Docker

Public docker images are managed by the so-called Docker Registry, and ROS images could be found in the OSRF respository on Docker Hub. A simple command

docker pull osrf/ros:kinetic-desktop

can easily download or “pull” the image of the Kinetic Desktop ROS. The download may take some time depending on the network speed. Note that the osrf/ros in the command refers to the name of the repository, and the kinetic-desktop after the colon is the tag or “branch”. A list of tags in the osrf/ros repository can be found here .

After pulling the osrf/ros:kinetic-desktop image, we can run it by

docker run -it--rm--name roscore osrf/ros:kinetic-desktop

A terminal will appear because of the '-it' option. This command actually creates a “container” called roscore due to the '–name roscore' option. The other option '–rm' tells docker that this container will be removed after it stops. Otherwise, it will be always there until we explicitly delete it by

docker rm roscore

In order to use ROS, we need to execute the roscore program first to start a master, a parameter server and a logging node. We can achieve this by executing the following code in the above terminal

./ros_entrypoint.sh
ip=$(hostname -I)exportROS_IP=$ip
roscore

After running roscore, the terminal won't accept any further commands, we could use docker exec to execute a command (e.g. bash) in the roscore container

docker exec-it roscore bash

The Talker-Listener Tutorial

After starting roscore, we can test a simple talker-listener example. First, start a listener by

However, docker in macOS itself runs inside a virtual machine. The above setting merely shares the same address with the virtual machine rather than the actual host. A temperary workaround is to use port mapping as