ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
1

docker containers with ROS2 are unable to communicate

asked 2022-05-25 14:56:05 -0500

jessicaycc gravatar image

I'm playing around with docker containers with ROS galactic with different network setup but I'm unable to get robot_container_1 and robot_container_2 to talk to each other.

I have robot_container_1 on two networks, rob_net and dev_net, making it kind of like a network hub, I have robot_container_2 on rob_net and robot_container_3 on dev_net. container 2 and 3 should be isolated from each other since they are on different networks but container_1 should be able to communicate with 2 and 3. However, for some reason container 2 is not hearing the topics that gets published from container 1 (container 3 is hearing fine).

I tried pinging container 1 from container 2 and vice versa and was able to confirm that they can ping each other.

Not sure why this is happening...

Dockerfile:

# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.234.0/containers/ubuntu/.devcontainer/base.Dockerfile
# [Choice] Ubuntu version (use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon): ubuntu-22.04, ubuntu-20.04, ubuntu-18.04
#ARG VARIANT="jammy"
#FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
FROM osrf/ros:galactic-desktop

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
#     && apt-get -y install --no-install-recommends <your-package-list-here>

RUN echo "source /opt/ros/galactic/setup.bash; echo ROS environment sourced" >> /home/.bashrc

docker-compose.yml:

version: '3'

networks:
  rob_net:
    name: robot_net
  dev_net:
    name: custom_net

services:
  robot_container_1:
    build: ./
    command: ros2 run demo_nodes_cpp talker
    networks:
      - rob_net
      - dev_net

  robot_container_2:
    build: ./
    command: ros2 run demo_nodes_cpp listener
    networks:
      - rob_net

  robot_container_3:
    build: ./
    command: ros2 run demo_nodes_cpp listener
    networks:
      - dev_net

Output in terminal:

Starting robot_machine_robot_container_3_1 ... done
Starting robot_machine_robot_container_2_1 ... done
Starting robot_machine_robot_container_1_1 ... done
Attaching to robot_machine_robot_container_3_1, robot_machine_robot_container_2_1, robot_machine_robot_container_1_1
robot_container_1_1  | [INFO] [1653500334.977882081] [talker]: Publishing: 'Hello World: 1'
robot_container_3_1  | [INFO] [1653500334.978566582] [listener]: I heard: [Hello World: 1]
robot_container_1_1  | [INFO] [1653500335.977827578] [talker]: Publishing: 'Hello World: 2'
robot_container_3_1  | [INFO] [1653500335.978318044] [listener]: I heard: [Hello World: 2]
robot_container_1_1  | [INFO] [1653500336.977837587] [talker]: Publishing: 'Hello World: 3'
robot_container_3_1  | [INFO] [1653500336.978320811] [listener]: I heard: [Hello World: 3]
robot_container_1_1  | [INFO] [1653500337.977835219] [talker]: Publishing: 'Hello World: 4'
robot_container_3_1  | [INFO] [1653500337.978418682] [listener]: I heard: [Hello World: 4]
robot_container_1_1  | [INFO] [1653500338.977836173] [talker]: Publishing: 'Hello World: 5'
robot_container_3_1  | [INFO] [1653500338.978390953] [listener]: I heard: [Hello World: 5]
robot_container_1_1  | [INFO] [1653500339.977832089] [talker]: Publishing: 'Hello World: 6'
robot_container_3_1  | [INFO] [1653500339.978390637] [listener]: I heard: [Hello World: 6]
robot_container_1_1  | [INFO] [1653500340.977834528] [talker]: Publishing: 'Hello World: 7'
robot_container_3_1  | [INFO] [1653500340.978335281] [listener]: I heard: [Hello World: 7]
robot_container_1_1  | [INFO] [1653500341.977838098] [talker]: Publishing: 'Hello World: 8'
robot_container_3_1  | [INFO] [1653500341.978314358] [listener]: I heard: [Hello World: 8]
robot_container_1_1  | [INFO] [1653500342.977831499] [talker]: Publishing: 'Hello World: 9'
robot_container_3_1  | [INFO] [1653500342.978335463] [listener]: I heard: [Hello World: 9]
robot_container_1_1  | [INFO] [1653500343.977838141] [talker]: Publishing: 'Hello World: 10'
robot_container_3_1  | [INFO] [1653500343.978360043] [listener]: I heard: [Hello World: 10]
robot_container_1_1  | [INFO] [1653500344.977782701] [talker]: Publishing: 'Hello World: 11'
robot_container_3_1  | [INFO] [1653500344.978188119] [listener]: I heard: [Hello World: 11]
robot_container_1_1  | [INFO] [1653500345.977757730] [talker]: Publishing: 'Hello World: 12'
robot_container_3_1 ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2022-05-31 21:14:12 -0500

ChuiV gravatar image

Since I don't see you specifically setting the rmw implementation (underlying dds vendor) you're using the default of rmw_cyclonedds_cpp. CycloneDDS (as of time of writing) only supports a single network interface. So since your container 1 has two networks (and thus two network interfaces) then cyclone is randomly selecting one. So it just so happens that container 1 and 3 talk because in container 1 cyclone happened to select the "rob_net" interface.

By adding an ENV RMW_IMPLEMENTATION=rmw_fastrtps_cpp to your Dockerfile, I was able to see:

Recreating rosquestions_robot_container_1_1 ...
Recreating rosquestions_robot_container_1_1
Recreating rosquestions_robot_container_2_1 ...
Recreating rosquestions_robot_container_3_1 ...
Recreating rosquestions_robot_container_2_1
Recreating rosquestions_robot_container_1_1 ... done
Attaching to rosquestions_robot_container_3_1, rosquestions_robot_container_2_1, rosquestions_robot_container_1_1
robot_container_1_1  | [INFO] [1654049287.167726590] [talker]: Publishing: 'Hello World: 1'
robot_container_3_1  | [INFO] [1654049287.168634709] [listener]: I heard: [Hello World: 1]
robot_container_2_1  | [INFO] [1654049287.168630309] [listener]: I heard: [Hello World: 1]
robot_container_1_1  | [INFO] [1654049288.167636021] [talker]: Publishing: 'Hello World: 2'
robot_container_3_1  | [INFO] [1654049288.167958630] [listener]: I heard: [Hello World: 2]
robot_container_2_1  | [INFO] [1654049288.167959462] [listener]: I heard: [Hello World: 2]
robot_container_1_1  | [INFO] [1654049289.167876872] [talker]: Publishing: 'Hello World: 3'
robot_container_2_1  | [INFO] [1654049289.168433694] [listener]: I heard: [Hello World: 3]
robot_container_3_1  | [INFO] [1654049289.168491234] [listener]: I heard: [Hello World: 3]
robot_container_1_1  | [INFO] [1654049290.167690598] [talker]: Publishing: 'Hello World: 4'
robot_container_2_1  | [INFO] [1654049290.168346310] [listener]: I heard: [Hello World: 4]
robot_container_3_1  | [INFO] [1654049290.168400415] [listener]: I heard: [Hello World: 4]
robot_container_1_1  | [INFO] [1654049291.167796768] [talker]: Publishing: 'Hello World: 5'
robot_container_3_1  | [INFO] [1654049291.168506268] [listener]: I heard: [Hello World: 5]
robot_container_2_1  | [INFO] [1654049291.168487552] [listener]: I heard: [Hello World: 5]
edit flag offensive delete link more

Comments

I see…this makes sense then.. Thank you!!

jessicaycc gravatar image jessicaycc  ( 2022-06-03 16:34:01 -0500 )edit

If this resolved your issue, please remember mark the answer as correct.
This helps us focus on remaining unanswered questions.

ruffsl gravatar image ruffsl  ( 2022-06-10 04:39:34 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-05-25 14:56:05 -0500

Seen: 82 times

Last updated: May 31