0
$\begingroup$

Rosanswers logo

I have been running ROS in a docker with the WSL 2 backend. For example:

docker run -it ros:noetic-ros-base

When I run roscore in this, I cannot see the ros topics from outside the docker, i.e. rostopic list in WSL fails. I have tried various ways of connecting the network to the WSL network, such as using the --network=host option, but to no avail. Part of my goal is to run gazebo in a docker and access it from within WSL, so I need to solve this network connection.

The question is: how can I run roscore from inside the docker, and be able to publish / subscribe to it from outside the docker in WSL?


Originally posted by Morris on ROS Answers with karma: 35 on 2020-10-15

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.