ROS 2 Learning Path  ยท  Illustrated Educational Book

Chapter Fifteen: Docker and CI/CD for ROS 2

From "it works on my laptop" to a deployable product
Prerequisite: Chapter 2 (Workspace/Package)
Ongoing project: the ARCHO fleet
Tools: Docker, GitHub Actions
Reading time: 100โ€“120 minutes
What we cover in this chapter 15.1Why Docker: "it works on my laptop" 15.2Dockerfile for ARCHO 15.3The GUI problem: RViz and Gazebo inside a Container 15.4Docker Compose for a full run 15.5CI/CD: automated testing on every code change 15.6A complete GitHub Actions pipeline 15.7What kinds of tests are needed 15.8Summary, glossary, and exercises

15.1Why Docker: "it works on my laptop"

Everything we've built for ARCHO so far has been tested on one specific development system with a specific version of Jazzy installed. But when a colleague wants to run the same project, or you want to deploy the same code to ten different ARCHO units, a classic problem appears.

โš ๏ธ The classic software problem

"It works on my laptop" but "it's broken on your system" โ€” because the ROS version, the package versions, or even the operating system version differ.

๐Ÿ“– What Docker is

Docker means packaging the project's entire software environment โ€” the ROS version, dependencies, packages, and environment variables โ€” into a reproducible Container. With Docker, ARCHO's runtime environment is exactly the same, whether it runs on your laptop, on a colleague's computer, or on the robot itself.

15.2Dockerfile for ARCHO

# Dockerfile
FROM ros:jazzy-ros-base
SHELL ["/bin/bash", "-c"]

RUN apt-get update && apt-get install -y \
    python3-colcon-common-extensions \
    ros-jazzy-navigation2 \
    ros-jazzy-nav2-bringup \
    ros-jazzy-slam-toolbox \
    ros-jazzy-robot-localization \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /archo_ws
COPY src /archo_ws/src

RUN source /opt/ros/jazzy/setup.bash && \
    colcon build --symlink-install

COPY docker/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["bash"]
#!/bin/bash
# docker/entrypoint.sh
set -e
source /opt/ros/jazzy/setup.bash
if [ -f /archo_ws/install/setup.bash ]; then
  source /archo_ws/install/setup.bash
fi
exec "$@"

15.3The GUI problem: RViz and Gazebo inside a Container

RViz and Gazebo (Chapters 6 and 7) need a real display, and Containers by default have no graphical interface at all. A few common approaches solve this problem:

ApproachBest for
X11 ForwardingLinux, fast for local development
Wayland ForwardingNewer Linux distributions
VNCRemote access or non-Linux operating systems
Gazebo on the Host, Nodes inside the ContainerGradual, simplest starting setup
๐Ÿ”ง Recommendation for getting started

The best starting point is to run Gazebo and RViz directly on Ubuntu and keep only the processing Nodes (Nav2, SLAM, controllers) inside Docker. Once this combination is stable, you can gradually containerize the whole system โ€” for example with a Dev Container in VS Code.

15.4Docker Compose for a full run

# docker-compose.yml
services:
  archo:
    build: .
    network_mode: host
    privileged: true
    volumes:
      - /dev:/dev
    environment:
      - ROS_DOMAIN_ID=20
โš ๏ธ Use network_mode: host with caution

This setting greatly simplifies DDS communication between Nodes (because the Containers sit directly on the Host network), but from a security and environment-isolation standpoint it must be used deliberately โ€” especially on a robot that is also connected to an external network.

๐Ÿ“– The golden sentence of this section

Docker doesn't simulate the robot itself; it makes the robot's software environment reproducible, deliverable, and deployable.

15.5CI/CD: automated testing on every code change

Meaning
CI (Continuous Integration)Every time code changes: Build, Test, and Lint run automatically
CD (Continuous Delivery/Deployment)Once CI passes: Package, Deploy, Release
๐Ÿ“– The golden sentence of this section

On a professional robot, testing isn't done just before final delivery; it is repeated automatically with every code change.

15.6A complete GitHub Actions pipeline

# .github/workflows/ros2-ci.yml
name: ROS 2 CI
on:
  push:
  pull_request:

jobs:
  build-and-test:
    runs-on: ubuntu-24.04
    container:
      image: ros:jazzy-ros-base
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install dependencies
        shell: bash
        run: |
          apt-get update
          apt-get install -y python3-colcon-common-extensions
          rosdep update
          rosdep install \
            --from-paths src \
            --ignore-src \
            -r -y

      - name: Build
        shell: bash
        run: |
          source /opt/ros/jazzy/setup.bash
          colcon build --event-handlers console_direct+

      - name: Test
        shell: bash
        run: |
          source /opt/ros/jazzy/setup.bash
          source install/setup.bash
          colcon test

      - name: Test results
        shell: bash
        run: |
          colcon test-result --verbose
flowchart LR A["Build passed?"] --> B["Test passed?"] --> C["Lint passed?"] --> D["Security scan passed?"] --> E["Merge allowed"] style E fill:#eafaf3,stroke:#0e9e6e

Note: the YAML file above only implements the Build and Test stages; the Lint and Security Scan stages are shown in this diagram as part of a complete, realistic Quality Gate, and adding them (for example with ament_lint or security-scanning tools) is left as an exercise.

15.7What kinds of tests are needed

Test typeWhat it checks
Unit TestA single small, isolated function or class
Integration TestCorrect communication between several Nodes
Launch TestDoes the whole system launch without errors?
Simulation TestDoes ARCHO correctly follow a specified path in Gazebo?
Regression TestDid a new change break a capability that used to work?
dev@archo:~$ docker build -t archo:jazzy . Successfully built 4a1e2c9b8f3d Successfully tagged archo:jazzy dev@archo:~$ docker compose up archo-1 | [INFO] [archo_bringup]: All nodes started successfully

15.8Chapter Fifteen summary

ARCHO's code is now packaged into a reproducible Container, and every code change is automatically built, tested, and checked before it is allowed to merge. That means delivering a new software version to a real ARCHO unit is no longer a manual, error-prone process from here on.

โœ… Learning checkpoint
  • I can explain exactly what problem Docker solves.
  • I know why running RViz and Gazebo inside a Container is challenging, and I can name several common solutions.
  • I can explain the difference between CI and CD.
  • I know the five common test types in professional ROS 2 projects.
๐ŸŒ Connection to the main project

ARCHO project now has a complete Dockerfile and Docker Compose setup for packaging its software, and every new commit is automatically built and tested in GitHub Actions.

What the next chapter adds

In Chapter Sixteen we step out of the software world and turn to ARCHO's own computing hardware: Jetson, Raspberry Pi, and ESP32 โ€” and which kind of processing each one is suited for.

Chapter Fifteen glossary

Docker
A tool for packaging a software environment into reproducible Containers.
Container
A lightweight, isolated runtime environment that includes all of an application's necessary dependencies.
Dockerfile
A text file that defines the steps for building a Docker image.
Docker Compose
A tool for defining and running several related Containers together.
CI (Continuous Integration)
The automated process of building and testing code with every change.
CD (Continuous Delivery/Deployment)
The automated process of packaging and releasing a new version once CI has passed.
Quality Gate
A set of conditions (Build, Test, Lint, Security) that must be satisfied before a Merge is allowed.

Chapter Fifteen common mistakes โ€” summary