Installing ROS 2 on macOS with Docker

Use Docker containers to get started with ROS development
José L. MillánJosé L. Millán ·
6 min read
Installing ROS 2 on macOS with Docker

Many native tools in the ROS ecosystem are only supported on Linux, often making robotics development on other operating systems difficult and tedious. To solve this developer friction, many roboticists have turned to container platforms like Docker to help them work cross-platform.

In this tutorial, we'll cover how you can quickly get up and running with ROS 2 on your macOS computer – all with the help of Docker containers.

Pulling a Docker image

Docker is a container platform that allows you to run an instance of an operating system on top of a host. It can empower teams to develop robots with unique operating system requirements, regardless of their own system specs, or to work with ROS distributions that are not supported on the host operating system.

A Docker image essentially packages software into standardized units for reproducible development and deployment. It's a lightweight, standalone, executable piece of software that includes everything needed to run an application – all the code, runtime, system tools, system libraries and settings.

Once you've installed Docker on your macOS machine, you can browse Docker Hub for available ROS images. Download – or "pull" – your desired image (in this case, ROS 2 Humble) from Docker Hub:

$ docker pull osrf/ros:humble-desktop

Verify that you've downloaded the correct image:

$ docker images
    REPOSITORY   TAG              IMAGE ID       CREATED        SIZE
    osrf/ros     humble-desktop   2d0812be07a4   3 weeks ago    3.57GB

Running the container

You can now use your downloaded images to start your ROS 2 container:

$ docker run -it --network=host --name=ros2 osrf/ros:humble-desktop bash

The -it option will open an Interactive Terminal, --network=host will open the same network to the container as the host, and the --name is useful to reopen the container later with the command docker exec -it <name> <cmd>.

Connect to the current container:

$ docker exec -it ros2 ./ bash

Publishing data in the container

In one terminal, publish a /chatter topic:

$ ros2 run demo_nodes_cpp talker

In another, verify that the message is being published:

$ ros2 topic echo /chatter

Verify that your ROS 2 container is still running:

$  docker ps
    CONTAINER ID   IMAGE                     COMMAND                  CREATED              STATUS              PORTS     NAMES
    67dc5c69822a   osrf/ros:humble-desktop   "/ …"   About a minute ago   Up About a minute             ros2

Use docker stop <name> and docker start <name> to stop and restart a container.

Visualizing the data in Foxglove Studio

Next, let's verify that we're publishing ROS messages in our Docker container by visualizing them in Foxglove Studio.

Let's pull the pre-built foxglove_bridge Docker images to run a ROS container and visualize its data in Foxglove Studio:

$ docker pull

To be able to connect Foxglove Studio to the container, you must publish the port 8765 on the Docker server with the -p 8765:8765 option.

Start the foxglove_bridge inside the container:

$ docker run --name=foxglove_ros2 -it -p 8765:8765

To test the connection, open a new Terminal window and connect to the current container. Then, run a static_transform_publisher to publish a simple transform:

$ docker exec -it foxglove_ros2 /./ bash
$ ros2 run tf2_ros static_transform_publisher --x 0 --y 1 --z 1 --roll 0 --pitch 0 --yaw 0  --frame-id base_link --child-frame-id sensor

Now, open your Foxglove Studio desktop app, initiate a Foxglove WebSocket connection with the default URL, add a Raw Messages panel listening to the /chatter topic, and verify that it shows the string message "hello!":

Foxglove WebSocket connection

You've now successfully run ROS 2 in a Docker container, and connected it to Foxglove Studio to visualize that data.

Stay tuned

With Docker containers, you can seamlessly continue development across different platforms – regardless of your robotics framework's constraints.

Reach out to us directly in our Slack community to ask questions or request a topic for the next tutorial. And stay tuned for a tutorial on installing ROS 2 on macOS with Docker.

Read more:

MCAP vs ROS 1 Bag Index Performance
MCAP vs ROS 1 Bag Index Performance

Comparing performance across indexes, remote storage, and summarization

Wyatt AltWyatt AltWyatt Alt
Esther WeonEsther WeonEsther Weon
8 min read
It's Time to Change the Status Quo for Stock Options
It's Time to Change the Status Quo for Stock Options

How we designed a more employee-friendly equity plan

Adrian MacneilAdrian MacneilAdrian Macneil
7 min read

Get blog posts sent directly to your inbox.

Ready to try Foxglove?

Get started for free