How to run ROS across docker containers?
How to run ROS in docker?
My ROS2 install doesn't allow to run hello world listener-talker example on my laptop.
To build-from-source and install ROS2, I followed instructions from https://docs.ros.org/en/rolling/Insta... in a Dockerfile (as I do not run ubuntu). I have sourced /home/ros2_rolling/install/local_setup.bash
. Following https://docs.ros.org/en/foxy/How-To-G... does not help (on my laptop, before running docker run
, I typed sudo ufw allow in proto udp to\from 224.0.0.0/4
and checked that MULTICAST
appears on sudo ifconfig docker0
) : ros2 multicast receive / send
doesn't work neither.
I've just tried with docker image osrf/ros2:nightly
: I get the exact same problems (I have sourced /opt/ros/rolling/setup.bash
).
What did I miss? What can I check/do to fix this problem? Could the firewall of my laptop be a problem: I guess no as everything should run inside docker (talker and listener are 2 containers in the same docker engine on my laptop). What could be wrong?
UPDATE
@achille: This works in the same container:
>> sudo docker run -it --rm osrf/ros:humble-desktop /bin/bash
root@ac235f33d39b:/# ros2 run demo_nodes_cpp listener & ros2 run demo_nodes_cpp talker
[2] 84
[INFO] [1674941340.675642006] [talker]: Publishing: 'Hello World: 1'
[INFO] [1674941340.676876651] [listener]: I heard: [Hello World: 1]
[INFO] [1674941340.677048550] [listener]: I heard: [Hello World: 1]
[INFO] [1674941341.675633255] [talker]: Publishing: 'Hello World: 2'
[INFO] [1674941341.676649526] [listener]: I heard: [Hello World: 2]
[INFO] [1674941341.676698121] [listener]: I heard: [Hello World: 2]
^C[INFO] [1674941342.516515910] [rclcpp]: signal_handler(signum=2)
But not in separate containers:
>> sudo docker run -it --rm osrf/ros:humble-desktop /bin/bash
root@914ba7f89cbb:/# ros2 run demo_nodes_cpp listener
>> sudo docker run -it --rm osrf/ros:humble-desktop /bin/bash
root@4fbc129d1650:/# ros2 run demo_nodes_cpp talker
[INFO] [1674940961.401879066] [talker]: Publishing: 'Hello World: 1'
[INFO] [1674940962.401838015] [talker]: Publishing: 'Hello World: 2'
[INFO] [1674940963.401874882] [talker]: Publishing: 'Hello World: 3'
[INFO] [1674940964.401859533] [talker]: Publishing: 'Hello World: 4'
^C[INFO] [1674940964.857425780] [rclcpp]: signal_handler(signum=2)
root@4fbc129d1650:/# ros2 multicast send
Sending one UDP multicast datagram...
root@914ba7f89cbb:/# ros2 multicast receive
Waiting for UDP multicast datagram...
What's wrong?
UPDATE
@achille: using --network host
doesn't help: I get the exact same result. Pretty surprised, years ago when I gave a try to ROS I do not remember I needed to play with network for listener-talker example. Looks like same question to me: hello-world listener-talker doesn't work in docker.
UPDATE
@GeorgNo: doesn't seem to help?!... Could the problem be related to iptables?... No idea why this is not working...
On a first terminal on my laptop:
>> sudo docker pull osrf/ros:humble-desktop
>> sudo docker run -it --rm --network host --env="RMW_IMPLEMENTATION=rmw_fastrtps_cpp" osrf/ros:humble-desktop ros2 run demo_nodes_cpp listener
^C[INFO] [1675116216.183522599] [rclcpp]: signal_handler(signum=2)
On a second terminal on the same laptop (no LAN):
>> sudo docker run -it --rm --network ...
This is not a docker or ROS issue as these things get tested daily by automated tests. Years ago docker worked the same way. Two separate containers simply don't allow communication between one another.
@achille:
--network host
doesn't help: what could I try next? What could help debug the problem?What's the output of
docker network inspect bridge
after running both containers in separate terminals? It should show the two containers. Also make sure you have the latest version of docker installed. Does this error happen on a different machine or just on your laptop?