ROS with Docker
The following tutorial is a description of how I’ve got started with ROS.
Meanwhile, I use my own Dockerfiles to use ROS (e.g., run demos with Daisy) which saves some time (specifying options, e.g., environment variables, working directory, or installing packages) and uses x11docker for GUI tools (I strongly recommend!).
Installation
-
Install docker (see installation instructions for your platform on docker docs - About Docker CE and post-installation steps).
- If you want to use ROS GUI tools build a custom docker image
(there are no official desktop-full images?):
$ cat Dockerfile FROM ros:melodic RUN apt-get update && apt-get install -y \ ros-melodic-desktop-full $ docker build -t ros:melodic-desktop-full .
If you only use the CLI, simply pull the ROS docker image:
$ docker pull ros:melodic
- Run ROS container:
$ docker run \ -it \ -v ~/catkin_ws:/root/catkin_ws \ -v ~/.ssh:/root/.ssh \ --network host \ --env ROS_MASTER_URI=http://<your hostname>:11311 \ --name ros ros:melodic[-desktop-full]
This command starts the ROS docker image
ros
in an interactive terminal mode (-i -t
) and mounts the host catkin workspace~/catkin_ws
to the home directory of the running container. Note, mounting does not resolve symlinks!The container uses the host’s network with no isolation (!) (as if the container processes would run on the host) using the host’s ssh configuration,
/etc/hosts
and hostname. The environment variable of the master URI is set, however, you might have a ros-entrypoint-script sourcing the workspaces anyway where you can add the export of the variable.It is convenient to assign a name to the container:
- to start another shell in the same container (this is not the typical
Docker way to do it – one process per container).
$ docker exec -it ros bash
- to stop the container.
$ docker stop ros
- to restart the container.
$ docker start ros
- to start another shell in the same container (this is not the typical
Docker way to do it – one process per container).
Usage Examples
Useful Docker commands
$ docker ps
$ docker ps -a
$ docker image ls
$ docker info
$ docker start <name>
$ docker exec -it <name> bash
$ docker stop <name>
$ docker container rm <name>
Inspect ROS nodes
On the host do:
- Run the ROS docker container created before:
$ docker start ros $ docker exec -it ros bash
Start some nodes in the container, e.g.:
$ source /opt/ros/melodic/setup.sh $ roscore & : $ rostopic pub -r 1 /test std_msgs/String "test"
- Run a docker container executing
rqt_graph
:$ docker run \ --net=host \ --user $(id -u) \ --env DISPLAY=$DISPLAY \ -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" \ --name rqt_graph \ ros:melodic-desktop-full \ rqt_graph
Use the host’s network as before to be part of the ROS network. The GUI shall be executed by the current user – not root (see also ROS Docker and GUI). Note that
--user=$USER
did not work for me. The name is unknown but the UID works. The display X server is shared.Give the container a name to be able to restart it later, select the desktop-full image and execute
rqt_graph
.
You may create an alias for convenience (in .bashrc
or similar):
alias docker_gui="docker run --net=host --user $(id -u) --env DISPLAY=$DISPLAY -v '/tmp/.X11-unix:/tmp/.X11-unix:rw'"
So you can later start a ROS GUI tool by:
$ docker_gui --name rqt_graph ros:melodic-desktop-full rqt_graph
You can then (re-)start rqt_graph
by:
$ docker start rqt_graph
Some GUI apps still make troubles (e.g., rviz). You may try x11docker.
Controlling Daisy
On the host do:
-
Setup the network with Daisy. You will need to connect to Daisy’s network install
openssh-server
and exchange SSH keys (see network setup). - Create a folder for your ROS workspace and download the general-ros-modules
repository including the tele-operation package:
$ mkdir -p ~/catkin_ws/src $ cd ~/catkin_ws/src $ git clone https://github.com/tuw-cpsg/general-ros-modules.git
- Run ROS in docker container created before.
$ docker start ros $ docker exec -it ros bash
In the container do:
- Install
p2os_msgs
(replacemelodic
with your distro) which is needed to communicate with the robot driver (e.g., motor control).bash-completion
is just for convenience.$ apt update $ apt install bash-completion $ apt install ros-melodic-p2os-msgs
- Initialize the ROS workspace (build and source):
$ source /opt/ros/melodic/setup.sh $ cd ~/catkin_ws $ catkin_make $ source devel/setup.sh
- Launch the teleop node to control Daisy:
$ roslaunch pioneer_teleop drive.launch \ notebook:=<your hostname> \ robot:=daisy robot-distro:=indigo robot-port:=/dev/ttyTHS1
References
- Docker Documentation
- docker docs - About Docker CE
- ROS Docker and GUI – outdated but still useful instructions to run ROS with Docker
- ROS Docker images – ROS images and examples
- ROS workspace – how to create a ROS workspace
- x11docker – the simple way to run GUI apps in docker
- Daisy Demos with Docker – images to control Daisy with ROS on docker
2019-02-08 | Denise Ratasich