Using ROS 2 in a Docker Container

In this tutorial will going to configure Docker for use a container with the latest stable version of ROS 2. This configuration have these features:

  • Launch terminals inside the container
  • Launch graphical applications from the container
  • Use your configured users inside the container
  • Share your home directory with the container


We need to install xorg-xhost utility for launching graphical apps inside the container. If you use Debian as OS, you can run the next instruction:

$ sudo apt install x11-xserver-utils

Installing Docker

For installing Docker we can follow the instructions from Docker official page. If you use Debian as OS, you can follow the next link:

If you use another OS, follow the instructions for that OS

Installing ROS 2 container

After installing Docker, we have to download the latest ROS stable to use with Docker. For these, run the next instruction:

$ sudo docker pull osrf/ros:dashing-desktop

Installing helper scripts

We going to use two helper scripts originally developed by Javier Peralta and modified for ROS 2, and The first one configures and runs the container, and the second creates an extra terminal inside the container. You can download these scripts from here.

After downloading the helper scripts, we going to give them execution permissions and move it to a defined directory for calling customs scripts and programs.

$ chmod +x
$ sudo mv /usr/local/bin

Running ROS 2 Container

For running ROS 2, we first execute


Running this first script will bring a terminal inside the container with all the ROS 2 setup already configured. If we need another terminal inside the container, we execute


Execute this script as many times we need. For exiting the container, we only need to exit from every terminal.

  • tutorials/ros2_in_docker.txt
  • Last modified: 2019/06/12 18:10
  • by amora