You're reading the documentation for a version of ROS 2 that has reached its EOL (end-of-life), and is no longer officially supported. If you want up-to-date information, please have a look at Galactic.
Running 2 nodes in 2 separate docker containers [community-contributed]
Open a terminal. Run the image in a container in interactive mode and launch a topic publisher (executable talker
from the package demo_nodes_cpp
) with ros2 run
:
docker run -it --rm osrf/ros:eloquent-desktop ros2 run demo_nodes_cpp talker
Open a second terminal. Run the image in a container in interactive mode and launch a topic subscriber (executable listener
from the package demo_nodes_cpp
) with ros2 run
:
docker run -it --rm osrf/ros:eloquent-desktop ros2 run demo_nodes_cpp listener
As an alternative to the command line invocation, you can create a docker-compose.yml
file (here version 2) with the following (minimal) content:
version: '2'
services:
talker:
image: osrf/ros:eloquent-desktop
command: ros2 run demo_nodes_cpp talker
listener:
image: osrf/ros:eloquent-desktop
command: ros2 run demo_nodes_cpp listener
depends_on:
- talker
To run the containers call docker-compose up
in the same directory. You can close the containers with Ctrl+C
.