DDS Config Setup between Docker Container and VM Running on Windows Host#

In order for ROS2 nodes to communicate between a Docker container running on a Windows host and a VM or WSL container running on the same host, you will need to reconfigure the ROS2 DDS middleware to communicate via unicast communication. To do so, you must configure the DEFAULT_FASTRTPS_PROFILES.xml document in both the VM and the Docker container -- this is done for you with the ros2/setup.sh script, however you will need to set some environment variables before running the script.
As of May 2022, Humble Hawksbill comes with FAST DDS as its default DDS middleware. If you are working with an older version of Humble, you will need to update it to the latest release.

Docker Container DDS setup#

  1. Allocate two UDP ports for unicast communication via the “docker run” command:

docker run ... -p 7410:7410/udp -p 7412:7412/udp ...

The -p flag publishes a port, which enables communication between the Docker container and the outside world

  1. Find the IP address of host.docker.internal and the IP address of the VM. Then, set these values as their respective environment variables. • The fastest way to find the IP address of host.docker.internal is to do a “ping host.docker.internal” within a Windows terminal. • To find the IP address of the VM, run “hostname -I” within the VM terminal.

docker run ... -e VM_IP=<.IP address of VM> -e DOCKER_CONTAINER_IP=

The -e flag sets environment variables. These will be used within the DDS config setup script.
host.docker.internal is a special DNS name that allows a Docker container to communicate with the Docker host.

  1. Go ahead and start the docker run command that you added flags to in steps 1 and 2.

shell docker run -e VM_IP=<IP address of VM> -e DOCKER_CONTAINER_IP=<host.docker.internal IP address> -p 7410:7410/udp -p 7412:7412/udp --gpus=all -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" -e DISPLAY airsim_binary:22.04-cudagl11-x11 bash

  1. Once the Docker container has started, navigate to the ros2 folder within the AirSimExtensions repository and open the setup.sh file. By default, the ports from step 1 are set as port_one=7410 and port_two=7412. If you chose any ports other than 7410 and 7412 in step one, you’ll need to change port_one and port_two to whatever you set them as during the docker run command. Save and exit.
  2. Run ./setup.sh – this will configure the ROS2 DDS middleware to communicate via unicast instead of multicast. Once this has completed, a file called DEFAULT_FASTRTPS_PROFILE.xml should appear in the ros2 folder. Open this file to verify that the address and port fields have been configured correctly. It should look something like this:

DDS config file for docker container

VM DDS setup#

  1. Navigate to the AirSimExtensions/ros2 folder from within the VM environment. If you are using any ports other than the default 7410 and 7412, once again, make these changes within the ros2/setup.sh file.
  2. Save and exit script, then run ./setup.sh. No need to create or modify environment variables – the script does this automatically on the VM.

DDS config file for VM

  1. Once the DEFAULT_FASTRTPS_PROFILES.xml file has been configured in both the Docker container and the VM, it is time to test ROS2. Note, in order for unicast communication to work properly, all nodes must be run in the Docker container before they are run on the VM. Try the ros2 run demo_nodes_py listener / ros2 run demo_nodes_py talker example to verify communication between the Docker container and the VM.