Tiryoh / docker-ros2-desktop-vnc

🐳 Dockerfiles to provide HTML5 VNC interface to access Ubuntu Desktop + ROS 2
https://memoteki.net/archives/2955
Apache License 2.0
408 stars 82 forks source link

Unable to communicate with ROS 2 system outside of docker container. #145

Closed cardboardcode closed 6 months ago

cardboardcode commented 6 months ago

:blush: Once again, thank you for the help in a previous issue @Tiryoh.

This repository has been very helpful thus far, particularly for those getting started with ROS 2 in general and do not want to worry about dependency conflict and environmental setup.

Issue Description

Attempting to run the docker Container does not allow ROS 2 nodes to communicate outside of it on the Host.

The reason why this could be important for it to be able to do so is such that ROS 2 systems developed within the Container can interact and thus integrate better with ROS 2 systems running outside of it.

Steps To Reproduce :hammer:

1. Download repository:

cd $HOME
git clone https://github.com/Tiryoh/docker-ros2-desktop-vnc.git --depth 1 --single-branch

2. Build tiryoh/ros2-desktop-vnc:humble-amd64 docker image:

cd $HOME
cd docker-ros2-desktop-vnc/humble
docker buildx build --platform=linux/amd64 --progress=plain -t tiryoh/ros2-desktop-vnc:humble-amd64 .

3. Build docker container:

docker run -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m tiryoh/ros2-desktop-vnc:humble-amd64

4. Access the docker VNC Container:

Open your preferred browser and go to http://127.0.0.1:6080/

5. Within the VNC Container, run demo_node_cpp's talker node:

# In VNC Container, open a new terminal
source /opt/ros/humble/setup.bash
ros2 run demo_node_cpp talker

5. On Host, run demo_node_cpp's listener node:

# In Host, open a new terminal
source /opt/ros/humble/setup.bash
ros2 run demo_node_cpp listener

Expected Behaviour :green_circle:

While the talker ROS 2 node produces the following output in Container:

[INFO] [1710645559.924575295] [talker]: Publishing: 'Hello World: 1'
[INFO] [1710645560.924465180] [talker]: Publishing: 'Hello World: 2'
[INFO] [1710645561.924515463] [talker]: Publishing: 'Hello World: 3'
[INFO] [1710645562.924504052] [talker]: Publishing: 'Hello World: 4'
...

The listener ROS 2 node in Host should output the following similar output:

[INFO] [1710645638.035280113] [listener]: I heard: [Hello World: 1]
[INFO] [1710645639.035206794] [listener]: I heard: [Hello World: 2]
[INFO] [1710645640.035271774] [listener]: I heard: [Hello World: 3]
[INFO] [1710645641.035294416] [listener]: I heard: [Hello World: 4]
...

Actual Behaviour :red_circle:

While the talker ROS 2 node produces the following output in Container:

[INFO] [1710645559.924575295] [talker]: Publishing: 'Hello World: 1'
[INFO] [1710645560.924465180] [talker]: Publishing: 'Hello World: 2'
[INFO] [1710645561.924515463] [talker]: Publishing: 'Hello World: 3'
[INFO] [1710645562.924504052] [talker]: Publishing: 'Hello World: 4'
...

Running ros2 run demo_nodes_cpp listener in Host does not output anything.

Remarks :speech_balloon:

Will be updating below shortly with my own attempts to debug the issue. I am aware of the changes suggested in Issue #138. However, implementing them only resolved the issue partially as you will see below in my various attempts.

I believe, by resolving this issue, it could make it even easier to develop ROS 2 applications for many users since many developers prefer a GUI-based workflow, similar to what is achieved in this repository.

Appreciate any help on this issue. Thank you :pray:

cardboardcode commented 6 months ago

Debug Attempt 1

This attempt utilizes the built-in network domain feature in ROS 2 to help talker node in Container communicate with listener node in Host.

Results

Issue persists. :cry: :red_circle:. talker in Container still unable to send messages outside to listener on Host.

Steps To Reproduce

  1. Set up the Docker Image and Container
    Click here for setup steps [Same as above]

a. Download repository:

cd $HOME
git clone https://github.com/Tiryoh/docker-ros2-desktop-vnc.git --depth 1 --single-branch

b. Build tiryoh/ros2-desktop-vnc:humble-amd64 docker image:

cd $HOME
cd docker-ros2-desktop-vnc/humble
docker buildx build --platform=linux/amd64 --progress=plain -t tiryoh/ros2-desktop-vnc:humble-amd64 .

c. Build docker container:

docker run -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m tiryoh/ros2-desktop-vnc:humble-amd64

  1. Within the VNC Container, identify its IP address:
# Open new terminal
hostname -i

You should see something like 192.168.0.167.

  1. On Host, identify its IP address:
# Open new terminal
hostname -i

You should see something like 192.168.0.163.

  1. Verify that both Container and Host can ping each other:

Container :whale2:

# In VNC Container terminal
ping <ip_address_of_host>
# Eg. ping 192.168.0.163

Host :computer:

# In Host  terminal
ping <ip_address_of_container>
# Eg. ping 192.168.0.167

You should see that both commands are producing successful pings to show both Host and Container are connected.

  1. Set ROS_DOMAIN_ID to the same one on Host as on Container and run the respective talker and listener nodes:

Container :whale2:

# In VNC Container terminal
export ROS_DOMAIN_ID=5
source /opt/ros/humble/setup.bash
ros2 run demo_nodes_cpp talker

Host :computer:

# In Host  terminal
export ROS_DOMAIN_ID=5
source /opt/ros/humble/setup.bash
ros2 run demo_nodes_cpp listener

References

  1. ROS2 Multiple Machines Tutorial (including Raspberry Pi)
cardboardcode commented 6 months ago

Debug Attempt 2 [Solution] :sparkles:

This attempt runs the docker Container in network_mode:host in order to allow talker node in Container communicate with listener node in Host.

Results :green_circle: :relaxed:

Issue is resolved. talker in Container is able to send messages outside to listener on Host.

Steps To Reproduce :hammer:

1. Download repository:

cd $HOME
git clone https://github.com/Tiryoh/docker-ros2-desktop-vnc.git --depth 1 --single-branch

2. Modify line 45 - 49 of humble/entrypoint.sh as follows:

if [ $(uname -m) = "aarch64" ]; then
    LD_PRELOAD=/lib/aarch64-linux-gnu/libgcc_s.so.1 vncserver :5 -geometry 1920x1080 -depth 24 -fg
else
    vncserver :5 -geometry 1920x1080 -depth 24 -fg
fi

3. Modify line 61 of humble/entrypoint.sh to the following:

command=gosu '$USER' bash -c "websockify --web=/usr/lib/novnc 6080 localhost:5905"

4. Build tiryoh/ros2-desktop-vnc:humble-amd64 docker image:

cd $HOME
cd docker-ros2-desktop-vnc/humble
docker buildx build --platform=linux/amd64 --progress=plain -t tiryoh/ros2-desktop-vnc:humble-amd64 .

5. Build and run docker Container:

docker run --ipc host --net host -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m tiryoh/ros2-desktop-vnc:humble-amd64

6. Run the talker and listener nodes in Container and Host respectively:

Container :whale2:

# In VNC Container terminal
source /opt/ros/humble/setup.bash
ros2 run demo_nodes_cpp talker

Host :computer:

# In Host  terminal
source /opt/ros/humble/setup.bash
ros2 run demo_nodes_cpp listener

Remarks :speech_balloon:

I was dumb. Forgot to do docker run with --ipc host as well as --net host parameter flag.

cardboardcode commented 6 months ago

As a quick add-on, while this issue has been resolved, it would be helpful if an investigation be made on how docker container latency may affect the rate at which messages are published from within Container and received in Host.