Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions _vale/config/vocabularies/Docker/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ Rekor
ROCm
rollback
rootful
rqt
runc
RViz
Ryuk
S3
scrollable
Expand All @@ -204,11 +206,13 @@ sysctl
sysctls
Sysdig
systemd
teleop
Testcontainers
tmpfs
Traefik
Trivy
Trixie
Turtlesim
Ubuntu
ufw
umask
Expand All @@ -231,6 +235,7 @@ WireMock
workdir
WORKDIR
Xdebug
XQuartz
youki
Yubikey
Zscaler
Expand Down
47 changes: 47 additions & 0 deletions content/guides/ros2/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
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: []
params:
tags: [frameworks]
time: 30 minutes
---

> **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.
- [Homebrew](https://brew.sh/) (macOS users): If you are using macOS, you must have Homebrew installed to manage dependencies.
- [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.
118 changes: 118 additions & 0 deletions content/guides/ros2/develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
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/
├── cache/
| ├── [ROS2_DISTRO]/
| | ├── build/
| | ├── install/
| | └── log/
| └── ...
|
├── src/
├── .devcontainer/
│ ├── devcontainer.json
│ └── Dockerfile
├── package1/
└── package2/

```

3. Explore the workspace layout
- `cache` : Stores build, install, and log artifacts for each ROS 2 distribution. Keeping these directories outside the source tree lets you change distributions without rebuilding everything from scratch.
- `src` : Contains all ROS 2 packages and the development container configuration. This directory is mounted into the container as the active workspace.
- `.devcontainer/` : Holds the configuration used by Visual Studio Code to open the workspace in a container.
- `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.
- `devcontainer.json` : Defines how Visual Studio Code builds, runs, and connects to the container. It configures the workspace location, user context, mounted directories, environment variables, networking options, installed extensions, and post-create setup commands.

## Open and build dev container

1. Install the `devcontainer` CLI:

- Linux / Windows
```console
$ sudo apt update && sudo apt upgrade
$ sudo apt install -y nodejs npm
$ sudo npm install -g @devcontainers/cli
```
- macOS
```console
$ brew install devcontainer
```

2. Execute the following commands to build and start the container:

```console
$ devcontainer up --workspace-folder ws/src

```

This command builds the Docker image defined in your `.devcontainer` folder 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.

3. Once the container is running, execute commands inside it using `exec`:

```console
devcontainer exec --workspace-folder ws/src /bin/bash
```

4. Inside the container terminal, verify the environment:

```console
$ ros2 --version
$ which colcon
```

All commands should execute successfully inside the container.

## Switch ROS 2 distributions

1. Create a new cache directory for the target distribution:

```console
$ mkdir -p ~/ws/cache/[ROS_DISTRIBUTION]/{build,install,log}
```

2. Update the cache paths in `src/.devcontainer/Dockerfile` and `src/.devcontainer/devcontainer.json`, changing from `humble` to `ROS_DISTRIBUTION`.

## Summary

In this section, you learned how to create a structured workspace with cache directories, write a Dockerfile with development tools and configure a dev container with `devcontainer.json`. 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.
77 changes: 77 additions & 0 deletions content/guides/ros2/run-ros2.md
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.
Loading