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

How to run ROS across docker containers?

asked 2023-01-23 13:07:29 -0500

fghoussen gravatar image

updated 2023-02-01 16:18:21 -0500

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 in a Dockerfile (as I do not run ubuntu). I have sourced /home/ros2_rolling/install/local_setup.bash. Following does not help (on my laptop, before running docker run, I typed sudo ufw allow in proto udp to\from 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?


@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?


@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.


@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 ...
edit retag flag offensive close merge delete


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 gravatar image achille  ( 2023-01-29 10:51:20 -0500 )edit

@achille: --network host doesn't help: what could I try next? What could help debug the problem?

fghoussen gravatar image fghoussen  ( 2023-01-29 11:49:17 -0500 )edit

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?

achille gravatar image achille  ( 2023-01-31 19:31:34 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2023-01-24 15:18:22 -0500

achille gravatar image

updated 2023-01-28 21:48:25 -0500

You shouldn't need to build ROS2 from source or the nightly or rolling containers (which are typically used for development & testing).

Follow the instructions in this docker + ros2 tutorial. I suggest trying the latest LTS version of ROS2, osrf/ros:humble (note ros, not ros2, the latter is reserved for development and testing images).

If that doesn't work, please add what exactly isn't working (error logs and behavior).

Edit to the OP's edit: That's a separate question. It won't work because you're launching two isolated containers which are designed to not share network information. If you want communication between them, you can specify a network interface they can use, e.g. --network host.

edit flag offensive delete link more


Thanks, I'll have a look asap. This is misleading: to use ros2, it's recommended to use ros image? Does this means ros contains both ros1 and ros2, and that ros2 contains only ros2?

fghoussen gravatar image fghoussen  ( 2023-01-27 15:48:17 -0500 )edit

This is documented on Dockerhub. ros contains your 'regular' images for ROS1 and ROS2 while ros2 only contains bleeding edge versions for development and testing.

achille gravatar image achille  ( 2023-01-27 23:43:56 -0500 )edit

answered 2023-01-29 13:27:33 -0500

GeorgNo gravatar image

This should help you out:

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: 2023-01-23 13:07:29 -0500

Seen: 136 times

Last updated: Feb 01