$npx -y skills add arpitg1304/robotics-agent-skills --skill docker-ros2-developmentBest practices for Docker-based ROS2 development including multi-stage Dockerfiles, docker-compose for multi-container robotic systems, DDS discovery across containers, GPU passthrough for perception, and dev-vs-deploy container patterns. Use this skill when containerizing ROS2 w
| 1 | # Docker-Based ROS2 Development Skill |
| 2 | |
| 3 | ## When to Use This Skill |
| 4 | |
| 5 | - Writing Dockerfiles for ROS2 workspaces with colcon builds |
| 6 | - Setting up docker-compose for multi-container robotic systems |
| 7 | - Debugging DDS discovery failures between containers (CycloneDDS, FastDDS) |
| 8 | - Configuring GPU passthrough with NVIDIA Container Toolkit for perception nodes |
| 9 | - Forwarding X11 or Wayland displays for rviz2 and rqt tools |
| 10 | - Managing USB device passthrough for cameras, LiDARs, and serial devices |
| 11 | - Building CI/CD pipelines with Docker-based ROS2 builds and test runners |
| 12 | - Creating devcontainer configurations for VS Code with ROS2 extensions |
| 13 | - Optimizing Docker layer caching for colcon workspace builds |
| 14 | - Designing dev-vs-deploy container strategies with multi-stage builds |
| 15 | |
| 16 | ## ROS2 Docker Image Hierarchy |
| 17 | |
| 18 | Official OSRF images follow a layered hierarchy. Always choose the smallest base that satisfies dependencies. |
| 19 | |
| 20 | ``` |
| 21 | ┌──────────────────────────────────────────────────────────────────┐ |
| 22 | │ ros:<distro>-desktop-full (~3.5 GB) │ |
| 23 | │ ┌────────────────────────────────────────────────────────────┐ │ |
| 24 | │ │ ros:<distro>-desktop (~2.8 GB) │ │ |
| 25 | │ │ ┌──────────────────────────────────────────────────────┐ │ │ |
| 26 | │ │ │ ros:<distro>-perception (~2.2 GB) │ │ │ |
| 27 | │ │ │ ┌────────────────────────────────────────────────┐ │ │ │ |
| 28 | │ │ │ │ ros:<distro>-ros-base (~1.1 GB) │ │ │ │ |
| 29 | │ │ │ │ ┌──────────────────────────────────────────┐ │ │ │ │ |
| 30 | │ │ │ │ │ ros:<distro>-ros-core (~700 MB) │ │ │ │ │ |
| 31 | │ │ │ │ └──────────────────────────────────────────┘ │ │ │ │ |
| 32 | │ │ │ └────────────────────────────────────────────────┘ │ │ │ |
| 33 | │ │ └──────────────────────────────────────────────────────┘ │ │ |
| 34 | │ └────────────────────────────────────────────────────────────┘ │ |
| 35 | └──────────────────────────────────────────────────────────────────┘ |
| 36 | ``` |
| 37 | |
| 38 | | Image Tag | Base OS | Size | Contents | Use Case | |
| 39 | |--------------------------|----------------|---------|---------------------------------------------|-------------------------------------| |
| 40 | | `ros:humble-ros-core` | Ubuntu 22.04 | ~700 MB | rclcpp, rclpy, rosout, launch | Minimal runtime for single nodes | |
| 41 | | `ros:humble-ros-base` | Ubuntu 22.04 | ~1.1 GB | ros-core + common_interfaces, rosbag2 | Most production deployments | |
| 42 | | `ros:humble-perception` | Ubuntu 22.04 | ~2.2 GB | ros-base + image_transport, cv_bridge, PCL | Camera/lidar perception pipelines | |
| 43 | | `ros:humble-desktop` | Ubuntu 22.04 | ~2.8 GB | perception + rviz2, rqt, demos | Development with GUI tools | |
| 44 | | `ros:jazzy-ros-core` | Ubuntu 24.04 | ~750 MB | rclcpp, rclpy, rosout, launch | Minimal runtime (Jazzy/Noble) | |
| 45 | | `ros:jazzy-ros-base` | Ubuntu 24.04 | ~1.2 GB | ros-core + common_interfaces, rosbag2 | Production deployments (Jazzy) | |
| 46 | |
| 47 | ## Multi-Stage Dockerfiles for ROS2 |
| 48 | |
| 49 | ### Dev Stage |
| 50 | |
| 51 | The development stage includes build tools, debuggers, and editor support for interactive use. |
| 52 | |
| 53 | ```dockerfile |
| 54 | FROM ros:humble-desktop AS dev |
| 55 | RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 56 | build-essential cmake gdb python3-pip \ |
| 57 | python3-colcon-common-extensions python3-rosdep \ |
| 58 | ros-humble-ament-lint-auto ros-humble-ament-cmake-pytest \ |
| 59 | ccache \ |
| 60 | && rm -rf /var/lib/apt/lists/* |
| 61 | ENV CCACHE_DIR=/ccache |
| 62 | ENV CC="ccache gcc" |
| 63 | ENV CXX="ccache g++" |
| 64 | ``` |
| 65 | |
| 66 | ### Build Stage |
| 67 | |
| 68 | Copies only `src/` and `package.xml` files to maximize cache hits during dependency resolution. |
| 69 | |
| 70 | ```dockerfile |
| 71 | FROM ros:humble-ros-base AS build |
| 72 | RUN apt-get update && apt-get install -y --no-install-recommends \ |