AljanabiM
robotics

Run ROS 2 in Docker

Published on
article-banner

Compared to ROS 1, ROS 2 can run on a wider range of operating system. However, the installation process requires many steps and for certain operating systems, such as macOS, you have to build from source.

A much smoother experience is to simply pull down a Docker image with ROS 2 pre-built, create a container and start working on your robotics application within a few minutes.

Here's a workflow you might find helpful:

Find the right Docker Image

  1. Checkout the available ROS2 releases in the official Github repo
  2. Find a corresponding Docker image from the Open Source Robotics Foundation (osrf) in Docker Hub. At the time of writing, ROS 2 Jazzy Jalisco is the most recent release so we'll pull down the corresponding desktop image
screenshot from docker hub
docker pull osrf/ros:jazzy-desktop-full

Working with ROS from within the container

Now we'll launch a listener-talker application with a talker in one terminal and a listener in another. Both nodes will be running on the same container.

docker run -it --name ros2-dev osrf/ros:jazzy-desktop-full
source ros_entrypoint.sh
ros2 run demo_nodes_py talker

docker run creates then starts the container. Moving on you can start the container with docker start -i ros2-dev. You exit the container with Ctrl+D.

Gif showing ros2 talker node

In a different terminal use the docker exec command to start a new bash session inside your running ROS container and launch the listener node.

docker exec -it ros2-dev bash
source ros_entrypoint.sh
ros2 run demo_nodes_py listener
Gif showing ros2 listener node

That's it. Now go build a cool robot application 🦾