ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
1

ROS2 foxy publish/subscribe between Docker container and Windows host

asked 2021-01-20 02:06:44 -0600

anastasiaPan gravatar image

updated 2021-01-25 03:25:24 -0600

Currently I have ROS2 foxy on a docker container and what I want to do is to publish and subscribe from the container to Windows side and the other way around as well. The container runs the tag base (link text). The installation I followed for ros2 foxy on windows is the official one (link text). Right now I am testing with ros2 examples (minimal publisher and minimal subscriber (link text) . I have tried to do this between two separate containers and it just works out of the box. It works if I do it between my ubuntu container and ubuntu host.

  • Docker networking in Windows:

First I tried to do the following https://docs.docker.com/docker-for-wi... (the I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST section) and it successfully connected to the host. But when running the publisher and subscriber nodes nothing goes through.

  • I also tried to publish the port:

    docker run -p 7412 my_ros_container

  • eProsima configuration:

One thing I tried but didn't fix is to change the RMW_IMPLEMENTATION to eProsima (link text). It should be the default value though. Having said that I am not at all experienced with DDS.

set RMW_IMPLEMENTATION=rmw_fastrtps_cpp

<?xml version="1.0" encoding="UTF-8" ?>
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
    <participant profile_name="ROS2_profile" is_default_profile="true">
        <rtps>
            <builtin>
                <initialPeersList>
                    <locator>
                        <udpv4>
                            <address>host.docker.internal</address>
                            <port>7412</port>
                        </udpv4>
                    </locator>
                </initialPeersList>
            </builtin>
        </rtps>
    </participant>
</profiles>
  • CycloneDDS configuration:

I also tried with Cyclone DDS setting it both in the ubuntu container and in my Windows system. And then I included:

<?xml version="1.0" encoding="UTF-8" ?>
<CycloneDDS xmlns="https://cdds.io/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://cdds.io/config https://raw.githubusercontent.com/eclipse-cyclonedds/cyclonedds/master/etc/cyclonedds.xsd">
  <Domain id="any">
    <General>
      <NetworkInterfaceAddress>auto</NetworkInterfaceAddress>
      <AllowMulticast>false</AllowMulticast>
    </General>
    <Discovery>
      <ParticipantIndex>auto</ParticipantIndex>
      <Peers>
        <Peer address="host.docker.internal"/>
      </Peers>
    </Discovery>
<Tracing><Verbosity>finest</Verbosity></Tracing>
  </Domain>
</CycloneDDS>

which also did not work but it produced a log file which I can copy paste as a comment if needed.

  • WSL2

I also tried this: https://github.com/docker/for-win/iss... but there is no default.conf in my container so I copied it under /etc. I also tried to replace host with host.docker.internal as suggested at: https://github.com/docker/for-win/iss...

So I created a default.conf as below:

server {
    listen       7412;
    listen  [::]:7412;
    server_name  host.docker.internal;
}

and run my image:

docker run --rm --net host --volume $PWD/default.conf:/etc/default.conf my_img

and when I try to communicate with curl it fails: curl http://127.0.0.1:7412
curl: (7) Failed to connect to 127.0.0.1 port 7412: Connection refused

This is my Dockerfile in case it is of any use:

> FROM ros:foxy as base
> 
> RUN apt-get update \
> ...
(more)
edit retag flag offensive close merge delete

Comments

Please edit your question with the full commands that you're running and any settings you've configured on you system relating to netowrking. This likely has to do with how you've configured your docker networking. @ruffsl suggested you look at https://github.com/docker/for-win/iss... for a potential issue if you're using WSL2.

tfoote gravatar image tfoote  ( 2021-01-25 02:22:07 -0600 )edit

Ok so I have updated my answer and I tried to be as thorough as possible.

anastasiaPan gravatar image anastasiaPan  ( 2021-01-25 03:26:13 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-01-28 05:24:04 -0600

anastasiaPan gravatar image
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

3 followers

Stats

Asked: 2021-01-20 02:06:44 -0600

Seen: 1,102 times

Last updated: Jan 28 '21