Hostname resolution between containers on a user-defined bridge network

So I have a ROS application where the master process (roscore) runs in a container, but I also want other containers on my Pi as well as on my development machine to be able to communicate with roscore.

The issue I’m having is that roscore attempts to connect to itself at the hostname on startup, and when I have host networking set, it always says it can’t resolve its own hostname, which I confirm by logging into the container and trying to ping itself.

I’ve tried several configurations and networking options, but this didn’t seem right, and I wanted to know if there was a reason for this, or a workaround.

1 Like

Hi @bathtubed could you post the Dockerfile and docker compose that you are using? I would like to try and replicate the issue you’re seeing.

Sure

This is the example docker compose file from the ROS wiki http://wiki.ros.org/docker/Tutorials/Compose

I’ve modified it, however, to use host networking due to the need to be able to communicate on unknown random ports with all the containers from outside the device.

version: '2'

services:
  ros-master:
    image: ros:kinetic-ros-core
    command: stdbuf -o L roscore
    network_mode: host
    restart: always

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

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