0
$\begingroup$

Rosanswers logo

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


Originally posted by thinwybk on ROS Answers with karma: 468 on 2018-01-25

Post score: 2

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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/userguide/networking/

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

Originally posted by tfoote with karma: 58457 on 2018-01-25

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by gvdhoorn on 2018-01-26:
Shouldn't this work out-of-the-box? All containers get placed on the same network in a default Docker network configuration.

Comment by thinwybk on 2018-01-27:
@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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.