Ask Your Question

Nodes can't talk to host when running ROS2 in Docker on MacOS

asked 2021-03-15 16:21:11 -0500

ozgudum gravatar image

I’m running ROS2 in docker container on MacOS. For ROS2, I basically modified the dockerfile and docker-compose files given here for ROS1:

ROS2 nodes as well as Rviz (through web browser using novnc) are running within the container with no issues. Current problem is that docker container can’t communicate with host machine. I have ROS2 nodes also running on MacOS host machine but nodes in the container can’t talk with them.

As far as I know, Docker creates a virtual network for the container and blocks all connection between the container and host machine. You can open particular ports when running the container but ROS2 is using multiple ports and port numbers are changing each time you run a new node.

So far, I tried running container with --network=host option but I can’t see topic published on host machine or vice a versa.

This might be a question about configuring Docker on MacOS but wondering if anybody had any experience on this?

edit retag flag offensive close merge delete


You can try and use tools like netcat with various Docker/VM network configurations to verify full connectivity:

ruffsl gravatar image ruffsl  ( 2021-03-17 17:15:11 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2021-03-23 22:15:27 -0500

amacneil gravatar image

Unfortuantely, --network=host isn't supported on macOS.


The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

You will have to expose each port manually to the host, using -p 80:80 (or -p 8000-9000:8000-9000 for a range of ports) syntax.

If you want containers to talk to each other, you can set up a container network and put multiple containers on the same network, but you won't be able to automatically see all of their ports from your macOS host.

edit flag offensive delete link more


Does Docker for MacOS have an equivalent network driver like that of the L2bridge for Windows hosts?

ruffsl gravatar image ruffsl  ( 2021-03-27 14:07:39 -0500 )edit

I am not aware of anything like that (if you find it let me know). The official docker docs say Because of the way networking is implemented in Docker Desktop for Mac, you cannot see a docker0 interface on the host. This interface is actually within the virtual machine.

amacneil gravatar image amacneil  ( 2021-03-30 20:20:12 -0500 )edit

Looks like you could use a classic linux VM (like the old Docker toolbox used) with a NIC instead of the current hypervisor approach (Docker for mac): . You just may have to manually install the docker VM if your using Big Sur or later:

ruffsl gravatar image ruffsl  ( 2021-03-31 00:34:49 -0500 )edit

answered 2021-07-01 08:52:50 -0500

Please find a solution to create a ros-docker-osx network using openVPN and fast dds discovery server in this repo:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2021-03-15 16:21:11 -0500

Seen: 314 times

Last updated: Mar 23