cyberbotics / webots_ros2

Webots ROS 2 packages
Apache License 2.0
402 stars 148 forks source link

Fix host IP address resolution for nodes running in Docker #889

Closed adamlm closed 8 months ago

adamlm commented 8 months ago

Description

This PR fixes a bug preventing webots_ros2_driver nodes running in a Docker image from launching and connecting to Webots running on a macOS host. The change set includes a new is_docker() function that checks if the process is running in an image. If so, the get_host_ip() will return host.docker.internal, Docker's special DNS name that resolves to the host's IP address.

Related Issues Closes #888

Affected Packages List of affected packages:

Tasks

Additional context I modeled the changes off the is_wsl() function; however, WSL has tighter integration with its host (Windows) than Docker Desktop. Docker and virtual machines seem like identical setups as far as this package is concerned.

I am not intimately familiar with the webots_ros2_driver package, so feel free to suggest modifications if there are more appropriate places for these changes.

omichel commented 8 months ago

Thank you for this contribution! This patch doesn't seem to be specific to macOS, right? It should work on Linux and Windows as well, isn't it?

adamlm commented 8 months ago

Thank you for this contribution! This patch doesn't seem to be specific to macOS, right? It should work on Linux and Windows as well, isn't it?

That's a good point. It works on Linux, but I don't have a Windows machine to test on. Getting it to work on Linux requires an extra step that we should probably document. The host.docker.internal DNS entry does not get added to the container automatically with Docker Engine like it does for Docker Desktop.

I can add extra documentation for this. Where is the best place to add it? The Wiki seems to point to the ROS documentation for installation guides.

omichel commented 8 months ago

Yes, the documentation should be written here and also probably we should update this one as well.