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 Rainer Rodrigues  ·  April 26, 2026  ·  12 min read



illustration of Docker and ROS robot arm
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 by 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 as we start from scratch.

The ROS Dependency Hell


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.

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 with 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.


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


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


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


Start the entire stack with a single command:

terminal bash

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


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


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.

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.

The Bottom Line



Robot arm in a production environment 

In the era of Software Defined Hardware, writing the code is only half the battle as 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 

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