Run ROS 2 in a container
Overview
In this section, you will run ROS 2 in an isolated Docker container using official ROS 2 images, verify that ROS 2 is working, and install additional ROS 2 packages for development and testing.
Run ROS 2 in a container
The fastest way to get started with ROS 2 is to use the official Docker image. To pull an image, start a container, and open an interactive bash shell:
Pull and run the official ROS 2 Docker image:
$ docker run -it ros:humbleThis guide uses the Humble distribution. You can replace
humblewith another supported distribution such asrolling,jazzy, oriron.NoteThis environment is temporary and does not maintain persistence. Any files you create or packages you install will be deleted once the container is stopped or removed.
Verify ROS 2 is working:
$ echo $ROS_DISTROYou should see output similar to:
humble
Install ROS 2 packages
The official ROS 2 images include core packages. To install additional packages, use the apt package manager:
Update the package manager:
$ sudo apt updateInstall the desired package:
$ sudo apt install $PACKAGE_NAME
Replace $PACKAGE_NAME with any package you want to install.
Some commonly used packages include:
ros-humble-turtlesim- Visualization and simulation toolros-humble-rviz2- 3D visualization toolros-humble-rqt- Qt-based ROS graphical toolsros-humble-demo-nodes-cpp- C++ demo nodesros-humble-demo-nodes-py- Python demo nodesros-humble-colcon-common-extensions- Build system extensions
Summary
In this section, you pulled an official ROS 2 Docker image, launched an interactive session, and extended the container's capabilities by installing additional ROS 2 packages using apt.
Next steps
In the next section, you will configure a persistent workspace to ensure your code and modifications are saved across sessions.