Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 1.18 KB

Run-2-nodes-in-two-separate-docker-containers.rst

File metadata and controls

32 lines (21 loc) · 1.18 KB

Run 2 nodes in 2 separate docker containers

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/ros2:ardent-basic 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/ros2:ardent-basic ros2 run demo_nodes_cpp listener

As 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/ros2:ardent-basic
    command: ros2 run demo_nodes_cpp talker
  listener:
    image: osrf/ros2:ardent-basic
    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.