ROS2-foxy nodes can't communicate through docker container border
I'm new to ROS2. I've got a somewhat weird setup that I'm trying to launch. My issue is that minimal publisher and subscriber from examples don't hear each other.
I've got a docker container, based on Ubuntu 18.04, with ROS2 Foxy installed from sources. This container has installed environment that I have to use, namely, CUDA 10.0 and some software using it.
This container is run on Ubuntu 20.04 host. This host has also installed ROS2 Foxy from Debian packages.
I run the container with --net host
, then launch minimal subscriber from examples in it.
Then I run minimal publisher on the host.
That is on host:
$ docker run --rm -it --net host container
In container:
# ros2 run examples_rclpy_minimal_subscriber subscriber_member_function
On host in another terminal:
$ source /opt/ros/foxy/setup.zsh
$ ros2 run examples_rclpy_minimal_publisher publisher_local_function
The issue is that the subscriber doesn't hear anything from the publisher. The same issue is observed, if I swap subscriber and publisher, that is run publisher in the container and subscriber on the host.
If I execute both subscriber and publisher in the container, subscriber hears it. On host:
docker exec -it container /bin/bash
In container:
ros2 run examples_rclpy_minimal_publisher publisher_local_function
And subscriber prints "I heard hello".
At the same time, multicast messages (ros2 multicast send
, ros2 multicast receive
) are sent and received successfully.
If I run the container without --net
key, then the subscriber running in it, sees messages from the publisher.
However, this limits usage of the container. It won't be seen from another PC.
I've pasted the minimal Dockerfile illustrating the issue at the bottom of this message (unfortunately, I cannot attach it).
I've also pushed image to the dockerhub, and it can be downloaded with the command docker pull wl2776/nvidia-ros:latest
What I've also checked.
Running netcat both in container and on host shows that the traffic is passed through the container boundary. If I replace subsriber in the container with netcat it prints several packets. That is, on host:
$ docker run --rm -it --net host container $ docker cp /bin/nc.openbsd container:/tmp
In container:
# /tmp/nc.openbsd -l -u -p 7400 | od -
On host in another terminal:
$ source /opt/ros/foxy/setup.zsh $ ros2 run examples_rclpy_minimal_publisher publisher_local_function
And I see several dumps from
nc
I've also tried the experiment with minimal publisher and subscriber using docker image tagged
osrf/ros:foxy-desktop
from dockerhub. Everything has worked perfectly.When minimal subscriber runs in the container, its node and topic are seen on the host. On host, while subscriber in the container is running:
$ ros2 topic list /parameter_events /rosout /topic $ ros2 node list /minimal_subscriber
If I stop minimal subsriber in the container with Ctrl-C, then it disappears from
ros2 node list
Sniffing packets with
tcpdump
shows that subscriber in OSRF's container sends RTPS packets with version 2.3, but mine - with version 2.2. They also have different sizes (252 bytes from OSRF's ...
I tried to reproduce on top of an 18.04 docker container, but the examples work for me (publishing from host and subscribing from inside the Docker container). Here's the Dockerfile I used.
I've built an image from your Dockerfile. Still the same issue. Did you use
--net host
? It is important.Everything works without
--net host
, but fails, if network isolation is turned off.Did you find a solution or could you isolate the problem? I have the same issue. Without --net host the communication works, but of course only isolated and not together with another computer in the network.
I think, the issue is in FastRTPS. If at least one of nodes (host or containerized, no matter) switches to CycloneDDS, the "hello" messages become heard. Here is the link to discussion on Github: https://github.com/eProsima/Fast-DDS/... They have deleted my comment that everything works, if I switch to CycloneDDS.