#!/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" "$@"