From 709a55f460d98d71578c0dd5d03fa317f3310ca9 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 12 Dec 2025 19:45:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=85=AC=E7=BD=91ip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/docker-compose_dokploy.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/main/docker-compose_dokploy.yml b/main/docker-compose_dokploy.yml index 32a432091..4692c6ee7 100644 --- a/main/docker-compose_dokploy.yml +++ b/main/docker-compose_dokploy.yml @@ -32,6 +32,33 @@ services: - REGION=LOCAL healthcheck: disable: true + # 容器启动时自动获取公网 IP 并设置环境变量(使用 Python,无需 curl) + command: + - sh + - -c + - | + get_public_ip() { + python3 -c " + import urllib.request + def get_ip(): + for url, timeout in [('http://169.254.169.254/latest/meta-data/public-ipv4',2),('https://ifconfig.me',3),('https://api.ipify.org',3)]: + try: + req = urllib.request.Request(url, headers={'User-Agent': 'curl/7.68.0'}) + with urllib.request.urlopen(req, timeout=timeout) as r: + ip = r.read().decode().strip() + if ip: return ip + except: pass + return 'localhost' + print(get_ip()) + " + } + export PUBLIC_IP=$$(get_public_ip) + export WEBSOCKET_URL="ws://$${PUBLIC_IP}:8000/xiaozhi/v1/" + export OTA_URL="http://$${PUBLIC_IP}:8003/xiaozhi/ota/" + echo ">>> Detected PUBLIC_IP: $${PUBLIC_IP}" + echo ">>> WEBSOCKET_URL: $${WEBSOCKET_URL}" + echo ">>> OTA_URL: $${OTA_URL}" + exec python app.py volumes: # Configuration directory - /home/ubuntu/live-agent/main/xiaozhi-server/data:/opt/xiaozhi-esp32-server/data