Container communication with device on the same network

Hi all

I’ve just now gotten my Raspberry Pi 5 that I’m going to use for a robotics project. I’m going to do all the development on a separate PC (stationary or laptop) via SSH, but I’m unsure about how I can implement the following:

I need to be able to ping the container from the WSL on my PC (either scenario 1 or 2), and the WSL from the container before I can set up the ROS2 network. What’s the best way to approach this? Expose ports with “-p 80:80”? “–network host”? Create a separate docker network? macvlan? I’m quite lost. I’ve watched NetworkChuck’s video on Docker networking probably 5 times now but still don’t know how to approach this.

The WiFi hotspot on my laptop has the same name and password as my home network, which means that the raspberry will try to connect to whichever of them is available.

The reason I have a WSL with ROS2 on the PCs is because I don’t want to run Rviz/Gazebo on the raspberry.

Thoughts?

You can configure your Raspi to connect to router WiFi and laptop WiFi when available. Then you need to figure out the IP of the Raspi to connect from PC with SSH to Raspi OS. If you want to connect to (web) services in Docker, you should open ports.

I tried opening ports and tested communication with http servers and curl, but found no progress. I could never communicate TO the wsl, only OUT from it.

Today, I figured out a way to solve it.

Everything was caused by the fact that the WSL was not ‘visible’ to other devices on the same network. I could only reach it from the Windows host, since it had its own network(?) isolated from the LAN? Either way, I found a configuration for WSL that puts it “in the same spot” as the Windows host. Here’s what worked:

On the raspberry, make sure that the container is running with ‘–network host’. It should be able to ping your Windows PC.

In Windows, change/add a file ‘.wslconfig’ in %UserProfile% and add:

[wsl2]
networkingMode=mirrored

Running ‘ifconfig’ in the wsl after a restart should give the same information as ‘ipconfig’ would give in Windows.

Without ANYTHING else, I started a talker node in the wsl, and it appeared for the container on the raspberry with ‘ros2 topic list’. Talker/Listener ros communication works! The fact that I was only two lines of configuration away from this for several days is hilarious.

1 Like