ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

how to run roscore in docker in wsl

asked 2020-10-15 21:35:27 -0600

Morris gravatar image

updated 2020-10-15 21:38:34 -0600

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-10-16 07:51:25 -0600

Morris gravatar image

updated 2020-10-18 05:58:57 -0600

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.

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: 2020-10-15 21:35:27 -0600

Seen: 588 times

Last updated: Oct 18 '20