mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
The SIH container entrypoint resolves host.docker.internal via getent hosts and feeds the first result to mavlink -t and uxrce_dds_client -h. On Docker Desktop for Windows the lookup can return an IPv6 ULA first, and both PX4 modules only parse IPv4, so they error out with 'invalid partner ip' and PX4 boots with no working MAVLink or DDS link. Switch to getent ahostsv4, which only returns IPv4 records, so the IP injected into the startup scripts is always parseable. Signed-off-by: Ramon Roche <mrpollo@gmail.com>
36 lines
1.3 KiB
Bash
36 lines
1.3 KiB
Bash
#!/bin/sh
|
|
# Docker entrypoint for PX4 SITL containers.
|
|
#
|
|
# On Docker Desktop (macOS/Windows), host.docker.internal resolves to the
|
|
# host machine. We detect this and configure MAVLink + DDS to send to the
|
|
# host IP instead of localhost (which stays inside the container VM).
|
|
#
|
|
# On Linux with --network host, host.docker.internal does not resolve and
|
|
# PX4 defaults work without modification.
|
|
|
|
set -e
|
|
|
|
# Detect install prefix (SIH uses /opt/px4, Gazebo uses /opt/px4-gazebo)
|
|
if [ -d /opt/px4-gazebo ]; then
|
|
PX4_PREFIX=/opt/px4-gazebo
|
|
else
|
|
PX4_PREFIX=/opt/px4
|
|
fi
|
|
|
|
# Resolve host.docker.internal to an IPv4 address. mavlink and uxrce_dds_client
|
|
# only parse IPv4, and on Docker Desktop for Windows the default `getent hosts`
|
|
# lookup can return an IPv6 ULA first, which both modules then reject.
|
|
DOCKER_HOST_IP=$(getent ahostsv4 host.docker.internal 2>/dev/null | awk '/STREAM/ {print $1; exit}')
|
|
|
|
if [ -n "$DOCKER_HOST_IP" ]; then
|
|
# MAVLink: replace default target (127.0.0.1) with the Docker host IP
|
|
sed -i "s/mavlink start -x -u/mavlink start -x -t $DOCKER_HOST_IP -u/g" \
|
|
"$PX4_PREFIX/etc/init.d-posix/px4-rc.mavlink"
|
|
|
|
# DDS: point uXRCE-DDS client at the host
|
|
sed -i "s|uxrce_dds_client start -t udp|uxrce_dds_client start -t udp -h $DOCKER_HOST_IP|" \
|
|
"$PX4_PREFIX/etc/init.d-posix/rcS"
|
|
fi
|
|
|
|
exec "$PX4_PREFIX/bin/px4" "$@"
|