Containerizing ROS: Why Every Robotics Engineer Needs to Learn Docker

Robotics DevOps · Docker · ROS 2

Containerizing ROS: Why Every Robotics Engineer Needs to Learn Docker

By YOUR NAME  ·  April 26, 2026  ·  12 min read

๐Ÿณ Replace this block with your hero image Recommended: 1200 × 630 px illustration of Docker + ROS robot arm
Ad · Blogger Layout AdSense Gadget recommended here

If you have spent more than a week working with the Robot Operating System (ROS), you have inevitably uttered the most dangerous phrase in engineering: "But it works on my machine!"

Robotics is rapidly adopting a Software Defined Hardware paradigm. As systems grow more complex — integrating AI, computer vision, and intricate motion planning — managing software environments across different developers, simulators, and physical robots has become a serious challenge. The solution? Docker.

Who is this guide for? Robotics engineers and ROS developers at any level who want reproducible, portable, and CI/CD-ready development environments. No deep Docker knowledge required — we start from scratch.

The ROS Dependency Hell

๐Ÿ•ธ️ Replace with infographic ROS distro → Ubuntu version coupling diagram

ROS (both ROS 1 and ROS 2) is incredibly powerful, but it is notoriously tightly coupled to the host operating system. A specific ROS distribution demands a specific Ubuntu release:

ROS DistributionRequired UbuntuEOL
ROS 1 NoeticUbuntu 20.04 FocalMay 2025
ROS 2 HumbleUbuntu 22.04 JammyMay 2027
ROS 2 JazzyUbuntu 24.04 NobleMay 2029
ROS 2 RollingUbuntu 24.04 NobleOngoing

Add in custom drivers, specialized computer vision libraries like OpenCV or CUDA, and conflicting Python versions, and your environment becomes a fragile house of cards. When you hand your code to a colleague or deploy to a physical robot, those slight environmental differences lead to catastrophic runtime failures.

Affiliate

Recommended Resource: "Docker Mastery: with Kubernetes +Swarm" by Bret Fisher is the #1 Docker course on Udemy with 250,000+ students. Covers everything from basics to production-grade deployment.

View Course on Udemy →

Enter Docker: The Ultimate DevOps Tool for Robotics

Docker solves this by packaging your ROS application — libraries, system tools, code, and runtime — into a standardized unit called a container. Think of it as a shipping container for software: the same container works identically on your laptop, your teammate's workstation, a cloud simulator, or the robot's edge computer.

๐Ÿ”

Total Reproducibility

A container built on your laptop runs exactly the same way everywhere — no "works on my machine" ever again.

๐Ÿงช

Version Isolation

Run ROS 2 Humble and ROS 1 Noetic side-by-side without polluting your host OS.

Rapid Onboarding

New team members spin up the entire dev stack in minutes with one docker compose up command.

๐Ÿ”’

Reproducible CI/CD

Automate testing and deployment with the exact same environment in your GitHub Actions pipeline.

Ad · In-Article AdSense Unit

Getting Started: Your First ROS Docker Container

Step 1 — Pull the Official ROS Image

The Open Source Robotics Foundation (OSRF) maintains official ROS images on Docker Hub at osrf/ros. Pull your target distribution:

terminal bash
# Pull ROS 2 Jazzy (latest LTS)
docker pull osrf/ros:jazzy-desktop

# Or for ROS 2 Humble
docker pull osrf/ros:humble-desktop

# Quick sanity check — run ros2 topic list
docker run --rm -it osrf/ros:jazzy-desktop bash -c "source /opt/ros/jazzy/setup.bash && ros2 topic list"

Step 2 — Write Your Dockerfile

Create a Dockerfile at the root of your ROS workspace. This example adds a custom Python package and builds your ROS 2 package on top of the base image:

Dockerfile dockerfile
# ── Base image: ROS 2 Jazzy on Ubuntu 24.04 ──
FROM osrf/ros:jazzy-desktop

# Set the working directory
WORKDIR /ros2_ws

# Install system dependencies and Python packages
RUN apt-get update && apt-get install -y \
    python3-pip \
    ros-jazzy-cv-bridge \
    ros-jazzy-image-transport \
    && rm -rf /var/lib/apt/lists/*

RUN pip3 install --no-cache-dir \
    opencv-python-headless==4.9.0.80 \
    numpy scipy

# Copy your ROS package source code
COPY src/ ./src/

# Source ROS and build the workspace
RUN /bin/bash -c "source /opt/ros/jazzy/setup.bash \
    && colcon build --symlink-install"

# Automatically source the workspace on container start
RUN echo "source /ros2_ws/install/setup.bash" >> ~/.bashrc

CMD ["/bin/bash"]
Pro tip: Use multi-stage builds for production Use a builder stage to compile your packages and a lean final stage to run them. This can cut your final image size from 3 GB down to under 500 MB.

Step 3 — Manage Multi-Container Setups with Docker Compose

Real robotics stacks involve multiple nodes: a core ROS process, a simulation environment (like Gazebo), custom perception nodes, and a visualization tool like RViz. Docker Compose lets you define and run all of these together:

docker-compose.yml yaml
version: '3.8'

services:

  # ── ROS 2 core & custom nodes ──
  ros_core:
    build: .
    container_name: ros2_core
    environment:
      - ROS_DOMAIN_ID=0
    volumes:
      - ./src:/ros2_ws/src
      - /tmp/.X11-unix:/tmp/.X11-unix
    network_mode: host
    stdin_open: true
    tty: true

  # ── Gazebo Simulation ──
  gazebo:
    image: osrf/ros:jazzy-desktop
    container_name: gazebo_sim
    environment:
      - DISPLAY=${DISPLAY}
      - ROS_DOMAIN_ID=0
    volumes:
      - /tmp/.X11-unix:/tmp/.X11-unix
    command: bash -c "source /opt/ros/jazzy/setup.bash && ros2 launch my_robot sim.launch.py"
    network_mode: host
    depends_on:
      - ros_core

Start the entire stack with a single command:

terminal bash
docker compose up --build
Affiliate

Run your ROS simulations in the cloud: DigitalOcean Droplets are a cost-effective way to run containerized ROS environments and CI/CD pipelines. Get $200 in free credits for 60 days as a new user.

Get $200 Free Credits →

Unlocking CI/CD for Robotics

๐Ÿ”„ Replace with CI/CD diagram git push → GitHub Actions → Docker build → simulation test → deploy to robot

The real power of Docker unlocks when you move beyond your local machine. Here is a minimal GitHub Actions workflow that builds your container and runs ROS 2 tests on every push:

.github/workflows/ros-ci.yml yaml
name: ROS 2 CI

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  build-and-test:
    runs-on: ubuntu-24.04

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Build Docker image
        run: docker build -t ros2-ci:latest .

      - name: Run unit tests in container
        run: |
          docker run --rm ros2-ci:latest bash -c \
            "source /ros2_ws/install/setup.bash \
             && colcon test --packages-select my_robot_pkg \
             && colcon test-result --verbose"
GPU Access in Containers If your nodes use CUDA for inference (e.g., a YOLO-based perception node), you need the nvidia-container-toolkit installed on the host and --gpus all flag in your Docker run command. See the NVIDIA Container Toolkit docs for setup.

Best Practices at a Glance

  1. Pin image tags — Never use :latest in production. Use versioned tags like osrf/ros:jazzy-desktop-20250401 for full reproducibility.
  2. Layer caching — Copy package.xml and install dependencies before copying source code, so dependency layers are cached across builds.
  3. Use .dockerignore — Exclude build/, install/, log/, and .git/ to keep context sizes small and builds fast.
  4. Never run as root — Create a non-root user in your Dockerfile to avoid volume permission issues when bind-mounting your source code.
  5. Externalize config — Use environment variables and volume mounts for robot-specific config (URDF, params). Never bake them into the image.
Ad · In-Article AdSense Unit

ROS 1 vs ROS 2 — Docker Changes Everything

FeatureWithout DockerWith Docker
Environment setup for new dev2–3 days✓ 15 minutes
Run ROS 1 & ROS 2 side by side✗ Very difficult✓ Trivial
CI/CD on GitHub Actions✗ Complex setup✓ Native support
Deploy to edge robotError-prone✓ Consistent
Reproduce a bug from 6 months ago✗ Nearly impossible✓ Just run the old image
Affiliate

Highly recommended book: "Programming Robots with ROS" (O'Reilly) gives you a solid ROS foundation to pair with what you've learned here. Available on Amazon.

View on Amazon →

The Bottom Line

๐Ÿค– Replace with closing image Robot arm in a production environment

In the era of Software Defined Hardware, writing the code is only half the battle — deploying it reliably is the rest. Docker gives robotics engineers the exact tooling they need to stop fighting dependency errors and start building better robots.

The learning curve is gentle. Pull an official image, write a simple Dockerfile, and wire it up with Docker Compose. Within a week you will wonder how you ever worked without it.

Ready to containerize your ROS environment?

Follow along with the companion GitHub repo, or start with the official ROS Docker images.

View GitHub Repo Official ROS Images ↗
ROS 2 Docker Robotics DevOps Docker Compose CI/CD Gazebo ROS Jazzy Containerization

Disclosure: This post contains affiliate links. If you make a purchase through them, AppliedKaos may earn a small commission at no extra cost to you. All recommendations are based on genuine use and opinion.

Comments

Popular posts from this blog

Synthesizing SystemVerilog with Yosys on WSL

From Netlist to Silicon: Place and Route with NextPNR on WSL

Low-Latency Control on Open-Source FPGA tools