-
Notifications
You must be signed in to change notification settings - Fork 8.2k
docs: Add guide for running ROS2 with Docker #24108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+480
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b2b7c4e
docs: Add guide for running ROS2 with Docker
shakirth-anisha a356dec
Update Vale accept list with ROS2-specific terminology
shakirth-anisha 81bbf20
minor fixes to ros2 guide
shakirth-anisha 58a198a
refactor(ros2): replace devcontainers setup with Docker Compose
shakirth-anisha ecf589b
chore: ros2 guide: format, metadata, add hero img
dvdksn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --- | ||
| title: Introduction to ROS 2 Development with Docker | ||
| linkTitle: ROS 2 | ||
| description: Learn how to containerize and develop ROS 2 applications using Docker. | ||
| keywords: ros2, robotics, devcontainers, python, cpp, Dockerfile, rviz | ||
| summary: | | ||
| This guide details how to containerize ROS 2 applications using Docker. | ||
| toc_min: 1 | ||
| toc_max: 2 | ||
| languages: [python] | ||
| tags: [frameworks] | ||
| params: | ||
| time: 30 minutes | ||
| image: /images/guides/ros2.jpg | ||
| featured: true | ||
| --- | ||
|
|
||
| > **Acknowledgment** | ||
| > | ||
| > This guide is a community contribution. Docker would like to thank | ||
| > [Shakirth Anisha](https://www.linkedin.com/in/shakirth-anisha/) for her contribution | ||
| > to this guide. | ||
|
|
||
| [ROS 2](https://www.ros.org/) is a set of software libraries and tools for building robot applications. It uses Data Distribution Service (DDS) for real-time, secure communication between distributed nodes, making it ideal for robotics and autonomous systems. | ||
|
|
||
| --- | ||
|
|
||
| ## What will you learn? | ||
|
|
||
| In this guide, you'll learn how to: | ||
|
|
||
| - Use official ROS 2 base images from Docker Hub | ||
| - Run ROS 2 in an Ubuntu container | ||
| - Install ROS 2 packages and dependencies | ||
| - Set up a development container for local development | ||
| - Run a complete end-to-end example with Turtlesim | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before you begin, make sure you're familiar with the following: | ||
|
|
||
| - [Docker Desktop](https://docs.docker.com/desktop/): You must have Docker Desktop installed and running. | ||
| - [Docker concepts](/get-started/docker-concepts/the-basics/what-is-a-container.md): You must understand core Docker concepts, such as images and containers. | ||
| - [ROS 2 concepts](https://www.ros.org): Basic understanding of concepts like nodes, packages, topics, and services. | ||
|
|
||
| ## What's next? | ||
|
|
||
| Start by setting up your ROS 2 development environment using Docker and dev containers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| --- | ||
| title: Build and develop a ROS 2 workspace | ||
| linkTitle: Set Up ROS 2 workspace | ||
| weight: 15 | ||
| keywords: ros2, robotics, docker, dockerfile, devcontainer, vscode, workspace | ||
| description: Learn how to develop ROS 2 applications using a Docker based workspace and development containers. | ||
| --- | ||
|
|
||
| ## Overview | ||
|
|
||
| In this section, you will set up a ROS 2 workspace using Docker and development containers, review the workspace layout, open the workspace in Visual Studio Code, and edit and build ROS 2 projects inside the container. | ||
|
|
||
| --- | ||
|
|
||
| ## Get the sample ROS 2 workspace | ||
|
|
||
| A consistent workspace simplifies managing ROS 2 projects and build artifacts across different distributions. | ||
|
|
||
| 1. Open a terminal and clone the sample workspace repository: | ||
|
|
||
| ```console | ||
| $ git clone https://github.com/shakirth-anisha/docker-ros2-workspace.git | ||
| $ cd docker-ros2-workspace | ||
|
|
||
| ``` | ||
|
|
||
| Moving forward, Linux users can use the `ws_linux` folder, and macOS users can use `ws_mac`. | ||
|
|
||
| 2. Verify the workspace structure: | ||
|
|
||
| ```text | ||
| ws_linux/ | ||
| ├── compose.yml | ||
| ├── Dockerfile | ||
| └── src/ | ||
| ├── package1/ | ||
| └── package2/ | ||
|
|
||
| ws_mac/ | ||
| ├── compose.yml | ||
| ├── Dockerfile | ||
| └── src/ | ||
| ├── package1/ | ||
| └── package2/ | ||
|
|
||
| ``` | ||
|
|
||
| 3. Explore the workspace layout | ||
|
|
||
| - `compose.yml` : Defines how Docker Compose builds and runs the ROS 2 container, including mounts, environment variables, and networking settings. | ||
| - `Dockerfile` : Builds the ROS 2 development image. It uses an official ROS 2 base image, creates a non-root development user, and installs required system and ROS 2 dependencies. | ||
| - `src` : Contains all ROS 2 packages. This directory is mounted into the container as the active workspace. | ||
|
|
||
| ## Open and build the container | ||
|
|
||
| 1. Execute the following commands to build and start the container: | ||
|
|
||
| For Linux: | ||
|
|
||
| ```console | ||
| $ cd ws_linux | ||
| $ docker compose up -d | ||
| $ docker compose exec ros2 /bin/bash | ||
| ``` | ||
|
|
||
| For macOS: | ||
|
|
||
| ```console | ||
| $ cd ws_mac | ||
| $ docker compose up -d | ||
| $ docker compose exec ros2 /bin/bash | ||
| ``` | ||
|
|
||
| This command builds the Docker image defined in your `Dockerfile` and starts the container in the background. | ||
|
|
||
| > [!NOTE] | ||
| > | ||
| > Building the image may take several minutes during the first run | ||
| > as the CLI pulls the base ROS 2 image and installs required dependencies. | ||
| > Subsequent starts will be significantly faster. | ||
|
|
||
| 2. Once the container is running, execute commands inside it using `exec`: | ||
|
|
||
| ```console | ||
| $ docker compose exec ros2 /bin/bash | ||
| ``` | ||
|
|
||
| 3. Inside the container terminal, verify the environment: | ||
|
|
||
| ```console | ||
| $ echo $ROS_VERSION | ||
| $ which colcon | ||
| ``` | ||
|
|
||
| All commands should execute successfully inside the container. | ||
|
|
||
| ## Switch ROS 2 distributions | ||
|
|
||
| Update the base image in your `Dockerfile`, changing from `humble` to another distribution like `rolling`, `jazzy`, or `iron`. | ||
|
|
||
| ## Summary | ||
|
|
||
| In this section, you learned how to create a structured workspace, write a Dockerfile with development tools, and configure a Docker Compose setup. Your ROS 2 development environment is now ready with a consistent, reproducible setup across any machine. | ||
|
|
||
| ## Next steps | ||
|
|
||
| In the next section, you'll run a complete end-to-end example with Turtlesim. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| --- | ||
| title: Run ROS 2 in a container | ||
| linkTitle: Run ROS 2 | ||
| weight: 10 | ||
| keywords: ros2, robotics, docker, dockerfile, devcontainer, vscode, workspace | ||
| description: Run ROS 2 in an isolated Docker container using official ROS 2 images and install additional ROS 2 packages. | ||
| --- | ||
|
|
||
| ## 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](https://hub.docker.com/_/ros/). To pull an image, start a container, and open an interactive bash shell: | ||
|
|
||
| 1. Pull and run the official ROS 2 Docker image: | ||
|
|
||
| ```console | ||
| $ docker run -it ros:humble | ||
| ``` | ||
|
|
||
| This guide uses the Humble distribution. You can replace `humble` with another supported distribution such as `rolling`, `jazzy`, or `iron`. | ||
|
|
||
| > [!NOTE] | ||
| > | ||
| > This 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. | ||
|
|
||
| 2. Verify ROS 2 is working: | ||
|
|
||
| ```console | ||
| $ echo $ROS_DISTRO | ||
| ``` | ||
|
|
||
| You should see output similar to: | ||
|
|
||
| ```text | ||
| humble | ||
| ``` | ||
|
|
||
| ## Install ROS 2 packages | ||
|
|
||
| The official ROS 2 images include core packages. To install additional packages, use the `apt` package manager: | ||
|
|
||
| 1. Update the package manager: | ||
|
|
||
| ```console | ||
| $ sudo apt update | ||
| ``` | ||
|
|
||
| 2. Install the desired package: | ||
|
|
||
| ```console | ||
| $ 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 tool | ||
| - `ros-humble-rviz2` - 3D visualization tool | ||
| - `ros-humble-rqt` - Qt-based ROS graphical tools | ||
| - `ros-humble-demo-nodes-cpp` - C++ demo nodes | ||
| - `ros-humble-demo-nodes-py` - Python demo nodes | ||
| - `ros-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. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.