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

Network Mode:host breaks the VNC connection #138

Closed alex77272 closed 6 months ago

alex77272 commented 6 months ago

Is there a way to run the Docker in network_mode:host? Rather than the default bridge mode? When I do that, I can't connect to the VNC desktop viewer anymore.

XO30 commented 6 months ago

Hi @alex77272,

It sounds like a frustrating issue, and I'm sorry to hear it's not working out. The good news is that the container can indeed operate in network_mode=host, but it requires a couple of minor adjustments to avoid port conflicts with the host system. These adjustments can be achieved by modifying the entrypoint.sh script. Below, I've outlined the necessary changes: Original Code Block Adjustment:

From:

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

To:

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

This change switches the virtual display from 1 to 5. As a result, the VNC server will now operate on port 5905 instead of port 5901, helping to prevent conflicts with existing VNC servers. Additional Code Modification:

From:

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

To:

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

This ensures that the noVNC web UI is directly accessible on port 6080 and that noVNC looks for the VNC server on the newly defined port 5905.

With these changes, everything should work as intended. You can now access via http://localhost:6080/

Best regards,

Stefan

alex77272 commented 6 months ago

Wow, your help was incredibly valuable. Thank you for solving the Git issue. I've been struggling with it for hours and your guidance has made all the difference. I wish you all the best and once again, thank you so much.

Alex

Tiryoh commented 6 months ago

@XO30 Thanks for your support!