ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

How can I run two ROS2 nodes each in a separate docker container?

asked 2018-01-25 15:42:40 -0600

thinwybk gravatar image

updated 2018-01-25 15:44:40 -0600

I would like to run two ROS2 nodes, let's say listener and talker from the demo_nodes_cpp package each in a docker container (osrf/ros2:ardent-basic image).

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-01-25 17:03:43 -0600

tfoote gravatar image

updated 2018-01-26 14:29:56 -0600

The easiest approach will be to setup the two containers to be on the same network segment. There's lots of ways to do this the docker networking documentation is here: https://docs.docker.com/engine/usergu...

You'll likely want to use Docker Compose to automate the multi container launching. I recommend reading the Docker Compose Documenation

Update: @gvdhoorn is right that the new docker behavior is to default to running the containers on the same network.

I verifed I can just run this on one terminal

$ docker run -ti --rm osrf/ros2:ardent-full ros2 run examples_rclcpp_minimal_publisher publisher_member_function
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 0'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 1'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 2'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 3'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 4'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 5'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 6'
...

And in a 2nd terminal:

$ docker run -ti --rm osrf/ros2:ardent-full ros2 run examples_rclpy_minimal_subscriber subscriber_member_function
[INFO] [minimal_subscriber]: I heard: "Hello, world! 34"
[INFO] [minimal_subscriber]: I heard: "Hello, world! 35"
[INFO] [minimal_subscriber]: I heard: "Hello, world! 36"
[INFO] [minimal_subscriber]: I heard: "Hello, world! 37"
...
edit flag offensive delete link more

Comments

1

Shouldn't this work out-of-the-box? All containers get placed on the same network in a default Docker network configuration.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-26 03:15:22 -0600 )edit
1

@gvdhoorn@tfoote The network config was not clear to me. @tfoote Thanks for the snippet. BTW: The example can be executed with the image osrf/ros2-basic as well.

thinwybk gravatar image thinwybk  ( 2018-01-27 06:18:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-01-25 15:42:40 -0600

Seen: 2,978 times

Last updated: Jan 26 '18