docker containers with ROS2 are unable to communicate
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 ...