Running ROS Noetic in Docker: A Practical Guide for Simulation and Teleoperation

Intro

The Robot Operating System (ROS) is an essential platform for developing robotic applications. However, getting ROS up and running on various systems can be challenging due to issues like dependency conflicts, varying operating system versions, and hardware inconsistencies.

One way to simplify this is by using Docker, which allows you to containerize your ROS environment. This method provides a portable, isolated environment that can be shared across different machines without affecting your host system.

In this guide, we will walk through the process of setting up ROS Noetic inside a Docker container and using it to:

  1. Run ROS Noetic in Docker.
  2. Simulate a mobile robot using Gazebo.
  3. Control the robot with teleop_twist_keyboard.
  4. Customize launch files for different simulation environments.

Benefits of Using Docker for ROS:

  • Consistency: Docker ensures the environment is the same across all systems.
  • Portability: Easily share and deploy ROS applications without worrying about installation or configuration.
  • Cross-Platform: Works on Linux, macOS, and Windows, providing flexibility.
  • Isolation: Keeps your ROS environment separate from your host system, minimizing conflicts.

For more about Docker, visit the official Docker documentation.

Setting Up ROS Noetic in Docker

To begin, you need Docker installed on your machine. If you haven’t installed Docker yet, follow the official guide to install Docker.

Run a ROS Noetic Docker Container in your Windows Terminal

Start by pulling the official ROS Noetic image and running it in an interactive terminal:

docker run -it --name ros_container --net=host --privileged osrf/ros:noetic-desktop-full bash

Explanation of Parameters:

  • docker run -it: Launches the container in interactive mode.
  • --name ros_container: Assigns a custom name to the container for easy reference.
  • --net=host: Ensures that ROS nodes can communicate with each other on the same network as the host.
  • --privileged: Grants the container full access to the host’s devices, which is necessary for simulation.
  • osrf/ros:noetic-desktop-full: Uses the ROS Noetic image, which includes the desktop version with tools like Gazebo.

Once you execute this command, you’ll be inside the Docker container, where ROS Noetic is fully set up and ready to use.

Creating a ROS Workspace and Building Packages

A ROS workspace is essential for organizing your projects and packages. Here’s how you can set up a basic workspace:

Create and Build a Catkin Workspace

mkdir -p ~/Workspaces/smb_ws/src
cd ~/Workspaces/smb_ws
catkin_make
source devel/setup.bash

Running a Robot Simulation in Gazebo

To test ROS in a real-world scenario, we will simulate a Small Mobile Robot (SMB) in Gazebo, a popular robot simulation tool integrated with ROS.

Clone the SMB Simulation Repository

cd ~/Workspaces/smb_ws/src
git clone https://github.com/ethz-asl/smb_common.git

Build the Package

cd ~/Workspaces/smb_ws
catkin_make
source devel/setup.bash

Launch the Simulation

roslaunch smb_gazebo smb_gazebo.launch

Controlling the Robot with Teleoperation

To manually control the simulated robot, we’ll use the teleop_twist_keyboard package, which allows control via keyboard input.

Clone and Build the Teleoperation Package

cd ~/Workspaces/smb_ws/src
git clone https://github.com/ros-teleop/teleop_twist_keyboard.git
cd ~/Workspaces/smb_ws
catkin_make
source devel/setup.bash

Run the Teleoperation Node

rosrun teleop_twist_keyboard teleop_twist_keyboard.py

Use the W/A/S/D keys to move the robot forward, backward, left, and right, and the Q/E keys to rotate it.

Verifying and Debugging ROS Nodes

As with any ROS application, debugging is an essential part of development.
Here are some common commands to verify the status of your ROS nodes and topics.

Check Running ROS Nodes

rosnode list

Check Available ROS Topics

rostopic list

Publish Velocity Commands Manually

To control the robot directly via command line, you can publish velocity command

rostopic pub -r 10 /cmd_vel geometry_msgs/Twist '{linear: {x: 0.5, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.5}}'

This command will move the robot forward while rotating it at a rate of 0.5 radians per second.

Conclusion

In this guide, we’ve set up ROS Noetic in Docker and demonstrated how to simulate a robot in Gazebo, control it manually.

Further Resources

If you have any feedback or questions, feel free to reach out through the ROS Discourse.

Hope this helps :slightly_smiling_face:

1 Like

I want to Run ROS Jazzy Jalisco in Docker with Apple M2 chip. Can I follow the same procedure by just changing the ROS Noetic to Jazzy?

You should really be using ghcr.io/sloretz/ros:noetic-simulators-osrf image as it contains newer Gazebo versions than osrf/ros.

See Up-to-date Docker Images for Gazebo + ROS Using the OSRF Repo - General - Gazebo Community for details.

We run a ROS Jazzy devcontainer, I am able to start it on my M2 Mac, so yes you should have no problem.

1 Like

@jbcpollak: Thanks for your reply. Can you please share some more details or point to some blog or official/un official Dockerfile to run ROS2 Jazzy on Ubuntu 24.04.