This repository is intended as a template for getting ROS2 running in a Docker container with full support for containerized development using the Development Containers spec.
Launching the codebase is done through docker compose:
docker compose -f compose.launch.yaml up <service>
The launch services are defined at the top of compose.launch.yaml
.
All new services should extend the overlay
service in compose.base.yaml
. The overlay
image contains all code in src/
, but must be rebuilt to copy any new changes:
docker compose -f compose.launch.yaml build [service]
If additional dependencies are needed in addition to the code in src/
, add them to the dependencies.repos
file and rebuild. Dependencies are managed using vcstool, which is a common ROS tool to import external repositories into the workspace.
Development containers have been defined in compose.dev.yaml
that includes dev tools and a friendly environment. Configuration for VSCode and the devcontainer spec are included with useful extensions and settings. Changes in the dev container are synced back to the host folder.
- Install the Dev Containers extension. More Info
- Click the bottom left corner icon in the editor.
- Choose either Open Folder in Container or Reopen in Container if you already have the repository folder open.
For other editors, refer to editor documentation on Dev Containers.
Attaching to the container: To run commands in the container from an external terminal, run ./attach.sh
while in the repository folder.
Using Foxglove Studio: The dev configuration can launch a foxglove_bridge sidecar. Uncomment the service in compose.dev.yaml
to enable. Start Foxglove Studio on the host and connect to ws://localhost:8765 (the default).
The configuration consists of three docker compose files:
compose.base.yaml
: Contains base services for running the repository in ROS2compose.launch.yaml
: Contains launch services that extend the base services. These definitions are intended for production environments.compose.dev.yaml
: Contains development services built on the base services. These are run by the .devcontainer configuration. The dev container provides additional development packages and tools, a non-root user with sudo access, and volumes to sync code changes between the container and the host.
The compose.base.yaml
consists of three container definitions:
- base: Contains core ROS2 packages and dependencies
- overlay: Contains ROS2 packages from this repository
- dev: Contains extra tools for development
For production environments, only base and overlay are deployed, containing the minimum set of packages necessary for running on a robot.
Networking in ROS2 should work automatically between any running containers and the host. This makes it easy to run additional ROS2 packages such as visualization tools on the host. However, ensure that you are using the Cyclone DDS middleware on the host for communicating with Docker services through ROS2.
These resources helped define much of the basics in this template:
An Updated Guide to Docker and ROS 2 - Robotic Sea Bass