ROS2 communication between docker container and Matlab.

Hello,
I followed this guide to set up a docker container to run gazebo: https://www.mathworks.com/help/ros/ug/install-and-set-up-docker-for-ros-2-and-gazebo.html. I'm now trying to follow this guide to connect to the docker container from Simulink: https://www.mathworks.com/help/ros/ug/connect-to-a-ros-enabled-robot-from-simulink-over-ros2.html. I'm using an intel macOS with Sequoia.
The issue I'm having is that I'm not able to get the ros2 topics to show up in Matlab. They are showing correctly according to the guide inside the container, but on the matlab side they are not reflecting. I've set the domain ID on both sides to be 25 and to use rmw_fastrtps_cpp. On the matlab side the only topics that are being picked up are /parameter_events and /rosout.
Any insight into why Matlab is not picking up the topics that are reflecting inside the docker container would be greatly appreciated.
Thanks!

4 Comments

Hi Jason,
I have a few questions to help narrow down the issue:
  1. What command did you use to launch the Docker container?
  2. Are you able to ping the Docker container's IP address from the host machine?
  3. Are you using the Docker Desktop application?
Hi Abhishek,
I used this command to create the container:
docker run -it \
--name ros2_diff_drive \
-p 8080:8080 \
-p 5904:5904 \
-p 7400-7500:7400-7500 \
-p 11311:11311 \
-p 11511:11511 \
-v /dev/shm:/dev/shm \
mw_ros_jazzy
and once it's created I just use docker start ros2_diff_drive to start the container up.
I'm not able to ping the container. 100% packet loss.
I am using Docker Desktop. I'm using an Intel macOS running Sequoia. I believe the backend that is being used is Apple Virtualisation framework.
Thanks!
Could you try launching the container using the host network driver (--net=host)? This option was previously unavailable on macOS, but starting with Docker Desktop v4.34, it is now supported. Here is the link to example: https://docs.docker.com/engine/network/drivers/host/
Additionally, could you verify whether communication is working between two containers? For example, you can create two containers: run a publisher in one and a subscriber in the other. You may use the ROS 2 demo pub-sub example:
To create publisher:
source /opt/ros/jazzy/setup.bash
ros2 run demo_nodes_cpp talker
To create subscriber:
source /opt/ros/jazzy/setup.bash
ros2 run demo_nodes_cpp listener
I used the host network driver but am facing the same issues.
I created a new container using the same dockerfile and using host network and created a publisher and subscriber as you suggested. The subscriber is not picking up anything.

Sign in to comment.

Answers (0)

Products

Release

R2025a

Asked:

on 8 Aug 2025

Commented:

on 11 Aug 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!