I found a partial answer to this. The reason --network=host
option fails has to do with how Docker relates to WSL; I believe it is in a VM. Anyway, the host the container sees is actually the Windows host which has a different IP address than WSL.
The key to enable roscore
to communicate is to publish the port it uses, which is 11311
by default. Thus I can do:
docker run -it -p 11311:11311 ros:noetic-ros-base
Then doing roscore
in the container and rostopic list
in WSL will show the published topics.
The reason this is a partial answer is that it does not enable ROS publishing / subscribing between the container and WSL. This is because each topic is assigned a random port to communicate on, and only port 11311 has been shared between the Docker and WSL. I've seen a solution where you publish a particular port and require the node to use that port, but that is too clunky for my applications.
Edit: I think the best solution is to run Docker directly either in Windows or WSL with the --network=host
option:
docker run -it --network=host ros:noetic-ros-base
I can run roscore
in one container and publish / subscribe in another container. All the containers have the same IP address, so no need to adjust ROS_MASTER_URI
. The only downside as far as I can tell is that, while the containers can communicate with each other, they cannot communicate with nodes in WSL.
Originally posted by Morris with karma: 35 on 2020-10-16
This answer was ACCEPTED on the original site
Post score: 0