Running ROS 2 in Docker is a practical way to make robotics development more reproducible. Robotics projects often depend on specific Ubuntu versions, DDS settings, package combinations, and middleware behavior. Containers help reduce the classic “it works on my machine” problem.
Why ROS 2 and Docker Work Well Together
- You can standardize the development environment across machines.
- You can onboard collaborators faster.
- You can test builds in CI using the same container image.
- You can isolate dependencies for multiple robotics projects.
A Basic ROS 2 Dockerfile
FROM ros:humble
WORKDIR /ws
RUN apt-get update && apt-get install -y python3-colcon-common-extensions && rm -rf /var/lib/apt/lists/*
COPY . /ws
RUN . /opt/ros/humble/setup.sh && colcon build
CMD ["bash"]
This is only a starting point, but it shows the general pattern: start from a ROS base image, install required tools, copy the workspace, and build it.
Practical Challenges
Robotics containers are not always as simple as web application containers. You may also need to think about:
- GUI forwarding for RViz or Gazebo,
- access to USB devices and sensors,
- network configuration for DDS discovery,
- volume mounts for source code and logs.
A Useful Development Workflow
- Keep the source code mounted into the container during development.
- Use a stable base image for the ROS distribution.
- Separate frequently changing code from slower-changing dependencies to speed up rebuilds.
- Use Docker Compose or scripts to simplify multi-container robotics setups.
Final Thoughts
Docker is not a magic answer for robotics, but it is extremely helpful for reproducibility. When combined with ROS 2, it gives teams a cleaner and more portable development workflow, especially when projects grow beyond one machine or one engineer.