0
$\begingroup$

I'm trying to encapsulate my ROS nodes in docker containers for deployment, but I'm unable to contact the docker container from the host computer. I believe this issue is related to my docker configuration, but I've tried on multiple machines and got the same results each time. All the machines I tested on are running Ubuntu 20.04. My goal is to run my ros master and a handful of nodes from a computer with the IP 192.168.1.250 and allow those nodes to be accessible on my network. At the moment I'm attempting to make the example work just on my local machine. Here is my docker compose file:

version: '2' 

services:
  ros-master:
    image: ros:noetic-ros-core
    command: roscore
    network_mode: "host"
    environment:
      - "ROS_MASTER_URI=http://localhost:11311"
    pid: "host"
    restart: always

  talker:
    image: ros:noetic-ros-core
    depends_on:
      - ros-master
    environment:
      - "ROS_MASTER_URI=http://localhost:11311"
    command: rostopic pub /chatter std_msgs/String "hello" -r 1
    pid: "host"
    network_mode: "host"
    restart: always

  listener:
    image: ros:noetic-ros-core
    depends_on:
      - ros-master
    environment:
      - "ROS_MASTER_URI=http://localhost:11311"
    command: rostopic echo /chatter
    pid: "host"
    network_mode: "host" 
    restart: always

On my host machine I set ROS_MASTER_URI to http://localhost:11311/, attempting to list the topics returns:

matthew@Selkie:~/ros_docker_example$ rostopic list
ERROR: Unable to communicate with master!
```
However, if I do the same from within a container, everything works as expected: 
```
matthew@Selkie:~/ros_docker_example$ docker run -it --network=host ros:noetic-ros-core /bin/bash
root@Selkie:/# rostopic list
/chatter
/rosout
/rosout_agg

I've also tried to use the host computer's IP address for the master and ROS_IP with the following compose file:

version: '2'

services:
  ros-master:
    image: ros:noetic-ros-core
    command: roscore
    network_mode: "host"
    environment:
      - "ROS_MASTER_URI=http://192.168.1.250:11311"
      - "ROS_IP=192.168.1.250"
    pid: "host"
    restart: always

  talker:
    image: ros:noetic-ros-core
    depends_on:
      - ros-master
    environment:
      - "ROS_IP=192.168.1.250"
      - "ROS_MASTER_URI=http://192.168.1.250:11311"
    command: rostopic pub /chatter std_msgs/String "hello" -r 1
    pid: "host"
    network_mode: "host"
    restart: always

  listener:
    image: ros:noetic-ros-core
    depends_on:
      - ros-master
    environment:
      - "ROS_IP=192.168.1.250"
      - "ROS_MASTER_URI=http://192.168.1.250:11311"
    command: rostopic echo /chatter
    pid: "host"
    network_mode: "host" 
    restart: always

Which results in the following error inside the ros-master container:

Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

for errors by running:

    ping 192.168.1.250

For more tips, please see

    http://wiki.ros.org/ROS/NetworkSetup

The traceback for the exception was written to the log file

I've double checked that I've installed docker correctly (1). I've also tried modifying /etc/hosts and adding the host machine's IP as suggested in (2) using the extra_hosts directive suggested in (3). I'm not sure what I'm missing, any help would be appreciated.

$\endgroup$
1
  • $\begingroup$ I discovered that this issue was caused by installing the rootless docker daemon which could be reverted by running dockerd-rootless-setuptool.sh uninstall $\endgroup$ Feb 19 at 0:25

0

Your Answer

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

Browse other questions tagged or ask your own question.