Skip to content

Instantly share code, notes, and snippets.

@coolbotic
Last active February 10, 2025 23:31
Show Gist options
  • Save coolbotic/28db32f34ecb560aece100dcccb439e9 to your computer and use it in GitHub Desktop.
Save coolbotic/28db32f34ecb560aece100dcccb439e9 to your computer and use it in GitHub Desktop.

ROS2 Docker Gazebo Setup (MacOS)

tags: #osx #macos #arm #arm64 #docker #gazebo #ros2 #ros

(For Mac + ARM/M1/M2/M3/M4)

Both the (Official ROS Docker images)[https://hub.docker.com/_/ros] and osrf/ros images are do not always have the latest version of Gazebo or support for arm platforms. Official Docker images for ROS2 are available at: https://hub.docker.com/r/osrf/ros/tags/

Offical images: https://hub.docker.com/_/ros

[https://hub.docker.com/_/ros](Official ROS Docker images)

[https://github.com/osrf/docker_images/blob/master/ros/jazzy/ubuntu/noble/simulation/Dockerfile](Source Dockerfile)

This is the vairation of ROS2 that is installed

docker pull osrf/ros:jazzy-simulation

Better repo for ROS2 images: https://github.com/sloretz/ros_oci_images

x11 Forwarding

I was unable to get the Gazebo GUI (or rviz2) to work on MacOS with x11 forwarding enabled using xQuartz. https://medium.com/@viirya/setting-up-linux-gui-container-on-mac-728194b20e78

VNC

See example Dockerfile in this gist:

Build the image (See Dockerfile for details):

docker build -t gazebo-vnc:jazzy .

Launch Docker container:

docker run -d --rm -p 5900:5900 gazebo-vnc:jazzy
docker exec -it <CONTAINER_ID> bash

Quickly launch built in MacOS VNC client:

open "vnc://localhost:5900"

Test with:

gz sim shapes.sdf

Example of working Gazebo GUI

Local Gazebo Client

https://gazebosim.org/docs/latest/ros2_integration/

On the host machine:

brew tap osrf/simulation
brew install <your_version> # e.g. brew install gz-harmonic (See below to match your ROS2 version) 

# ROS2 Rolling = gz-iconic
# ROS2 Jazzy = gz-harmonic (*Tested & Working*)
# ROS2 Humble & Iron = ignition-fortress
# ROS2 Foxy & Noetic = ignition-citadel

Note: This takes a while to install.

Robostack

Resources

# Example Dockerfile for adding a VNC server to an existing image.
# Select your base image here:
FROM ghcr.io/sloretz/ros:jazzy-desktop-full
# Add anything else you need to install/do here
# Install required packages for VNC
RUN apt-get update && apt-get install -y \
x11vnc \
xvfb \
firefox \
mesa-utils \
libgl1-mesa-dri \
libgl1-mesa-dev \
libglu1-mesa \
xserver-xorg-core \
xserver-xorg-video-dummy \
x11-apps \
dbus-x11 \
xfce4 xfce4-goodies \
&& rm -rf /var/lib/apt/lists/*
# Create a VNC password
RUN mkdir ~/.vnc && x11vnc -storepasswd 1234 ~/.vnc/passwd
# Set the DISPLAY environment variable
RUN echo 'export DISPLAY=:1' >> ~/.bashrc
RUN echo 'source /ros_entrypoint.sh' >> ~/.bashrc
# Configure a virtual X server (Xvfb)
CMD Xvfb :1 -screen 0 1680x1050x24 & \
export DISPLAY=:1 && \
export LIBGL_ALWAYS_SOFTWARE=1 && \
dbus-launch --exit-with-session startxfce4 & \
x11vnc -display :1 -forever -passwd 1234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment