28 lines
1.2 KiB
Bash
28 lines
1.2 KiB
Bash
#!/bin/bash
|
|
NGINX_PID=$(ps -efL | grep "nginx" | grep -v grep | awk '{print $2}' | head -1)
|
|
echo "nginx PID: $NGINX_PID"
|
|
echo ""
|
|
echo "--- 1. Find host's IP from container's perspective ---"
|
|
# In docker, host gateway is usually 172.17.0.1 or 10.0.0.1
|
|
nsenter -t $NGINX_PID -n -- ip route 2>&1 | head -5
|
|
echo ""
|
|
echo "--- 2. Try various host IPs to find which one has port 3000 ---"
|
|
for IP in 10.0.4.1 172.17.0.1 172.19.0.1 host.docker.internal 10.0.0.1 172.18.0.1; do
|
|
result=$(nsenter -t $NGINX_PID -n -- curl -s -o /dev/null -w "%{http_code}" --max-time 3 http://$IP:3000/api/v1/banners 2>/dev/null)
|
|
echo "$IP:3000 -> HTTP $result"
|
|
done
|
|
echo ""
|
|
echo "--- 3. Find IP that gives 200 ---"
|
|
for IP in 10.0.4.1 172.17.0.1 172.19.0.1 172.20.0.1 10.0.4.2 10.0.0.1 192.168.0.1; do
|
|
result=$(nsenter -t $NGINX_PID -n -- curl -s -o /dev/null -w "%{http_code}" --max-time 2 http://$IP:3000/api/v1/banners 2>/dev/null)
|
|
if [ "$result" = "200" ]; then
|
|
echo "FOUND: $IP:3000 returns 200"
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
echo "--- 4. Find the host machine's main IP from openresty container ---"
|
|
nsenter -t $NGINX_PID -n -- cat /etc/hosts 2>&1
|
|
echo ""
|
|
nsenter -t $NGINX_PID -n -- ip addr 2>&1 | grep inet | head -10
|