Run ROS 2 in Docker
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
- Checkout the available ROS2 releases in the official Github repo
- 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
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 withdocker start -i ros2-dev
. You exit the container withCtrl+D
.
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
That's it. Now go build a cool robot application 🦾