Skip to content

Commit 414a617

Browse files
authored
Merge pull request #16 from Dokploy/15-failed-to-initialize-docker-swarm-on-ubuntu-2404-during-dokploy-installation
refactor: add fallback getIp
2 parents 74ca743 + b2dac5e commit 414a617

File tree

3 files changed

+114
-27
lines changed

3 files changed

+114
-27
lines changed

apps/website/public/canary.sh

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,50 @@ install_dokploy() {
4343
docker swarm leave --force 2>/dev/null
4444

4545
get_ip() {
46-
# Try to get IPv4
47-
local ipv4=$(curl -4s https://ifconfig.io 2>/dev/null)
46+
local ip=""
47+
48+
# Try IPv4 first
49+
# First attempt: ifconfig.io
50+
ip=$(curl -4s --connect-timeout 5 https://ifconfig.io 2>/dev/null)
51+
52+
# Second attempt: icanhazip.com
53+
if [ -z "$ip" ]; then
54+
ip=$(curl -4s --connect-timeout 5 https://icanhazip.com 2>/dev/null)
55+
fi
56+
57+
# Third attempt: ipecho.net
58+
if [ -z "$ip" ]; then
59+
ip=$(curl -4s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null)
60+
fi
4861

49-
if [ -n "$ipv4" ]; then
50-
echo "$ipv4"
51-
else
52-
# Try to get IPv6
53-
local ipv6=$(curl -6s https://ifconfig.io 2>/dev/null)
54-
if [ -n "$ipv6" ]; then
55-
echo "$ipv6"
62+
# If no IPv4, try IPv6
63+
if [ -z "$ip" ]; then
64+
# Try IPv6 with ifconfig.io
65+
ip=$(curl -6s --connect-timeout 5 https://ifconfig.io 2>/dev/null)
66+
67+
# Try IPv6 with icanhazip.com
68+
if [ -z "$ip" ]; then
69+
ip=$(curl -6s --connect-timeout 5 https://icanhazip.com 2>/dev/null)
70+
fi
71+
72+
# Try IPv6 with ipecho.net
73+
if [ -z "$ip" ]; then
74+
ip=$(curl -6s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null)
5675
fi
5776
fi
77+
78+
if [ -z "$ip" ]; then
79+
echo "Error: Could not determine server IP address automatically (neither IPv4 nor IPv6)." >&2
80+
echo "Please set the ADVERTISE_ADDR environment variable manually." >&2
81+
echo "Example: export ADVERTISE_ADDR=<your-server-ip>" >&2
82+
exit 1
83+
fi
84+
85+
echo "$ip"
5886
}
5987

6088
advertise_addr="${ADVERTISE_ADDR:-$(get_ip)}"
89+
echo "Using advertise address: $advertise_addr"
6190

6291
docker swarm init --advertise-addr $advertise_addr
6392

apps/website/public/feature.sh

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,50 @@ install_dokploy() {
4343
docker swarm leave --force 2>/dev/null
4444

4545
get_ip() {
46-
# Try to get IPv4
47-
local ipv4=$(curl -4s https://ifconfig.io 2>/dev/null)
46+
local ip=""
47+
48+
# Try IPv4 first
49+
# First attempt: ifconfig.io
50+
ip=$(curl -4s --connect-timeout 5 https://ifconfig.io 2>/dev/null)
51+
52+
# Second attempt: icanhazip.com
53+
if [ -z "$ip" ]; then
54+
ip=$(curl -4s --connect-timeout 5 https://icanhazip.com 2>/dev/null)
55+
fi
56+
57+
# Third attempt: ipecho.net
58+
if [ -z "$ip" ]; then
59+
ip=$(curl -4s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null)
60+
fi
4861

49-
if [ -n "$ipv4" ]; then
50-
echo "$ipv4"
51-
else
52-
# Try to get IPv6
53-
local ipv6=$(curl -6s https://ifconfig.io 2>/dev/null)
54-
if [ -n "$ipv6" ]; then
55-
echo "$ipv6"
62+
# If no IPv4, try IPv6
63+
if [ -z "$ip" ]; then
64+
# Try IPv6 with ifconfig.io
65+
ip=$(curl -6s --connect-timeout 5 https://ifconfig.io 2>/dev/null)
66+
67+
# Try IPv6 with icanhazip.com
68+
if [ -z "$ip" ]; then
69+
ip=$(curl -6s --connect-timeout 5 https://icanhazip.com 2>/dev/null)
70+
fi
71+
72+
# Try IPv6 with ipecho.net
73+
if [ -z "$ip" ]; then
74+
ip=$(curl -6s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null)
5675
fi
5776
fi
77+
78+
if [ -z "$ip" ]; then
79+
echo "Error: Could not determine server IP address automatically (neither IPv4 nor IPv6)." >&2
80+
echo "Please set the ADVERTISE_ADDR environment variable manually." >&2
81+
echo "Example: export ADVERTISE_ADDR=<your-server-ip>" >&2
82+
exit 1
83+
fi
84+
85+
echo "$ip"
5886
}
5987

6088
advertise_addr="${ADVERTISE_ADDR:-$(get_ip)}"
89+
echo "Using advertise address: $advertise_addr"
6190

6291
docker swarm init --advertise-addr $advertise_addr
6392

apps/website/public/install.sh

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,50 @@ install_dokploy() {
4242
docker swarm leave --force 2>/dev/null
4343

4444
get_ip() {
45-
# Try to get IPv4
46-
local ipv4=$(curl -4s https://ifconfig.io 2>/dev/null)
45+
local ip=""
46+
47+
# Try IPv4 first
48+
# First attempt: ifconfig.io
49+
ip=$(curl -4s --connect-timeout 5 https://ifconfig.io 2>/dev/null)
50+
51+
# Second attempt: icanhazip.com
52+
if [ -z "$ip" ]; then
53+
ip=$(curl -4s --connect-timeout 5 https://icanhazip.com 2>/dev/null)
54+
fi
55+
56+
# Third attempt: ipecho.net
57+
if [ -z "$ip" ]; then
58+
ip=$(curl -4s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null)
59+
fi
4760

48-
if [ -n "$ipv4" ]; then
49-
echo "$ipv4"
50-
else
51-
# Try to get IPv6
52-
local ipv6=$(curl -6s https://ifconfig.io 2>/dev/null)
53-
if [ -n "$ipv6" ]; then
54-
echo "$ipv6"
61+
# If no IPv4, try IPv6
62+
if [ -z "$ip" ]; then
63+
# Try IPv6 with ifconfig.io
64+
ip=$(curl -6s --connect-timeout 5 https://ifconfig.io 2>/dev/null)
65+
66+
# Try IPv6 with icanhazip.com
67+
if [ -z "$ip" ]; then
68+
ip=$(curl -6s --connect-timeout 5 https://icanhazip.com 2>/dev/null)
69+
fi
70+
71+
# Try IPv6 with ipecho.net
72+
if [ -z "$ip" ]; then
73+
ip=$(curl -6s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null)
5574
fi
5675
fi
76+
77+
if [ -z "$ip" ]; then
78+
echo "Error: Could not determine server IP address automatically (neither IPv4 nor IPv6)." >&2
79+
echo "Please set the ADVERTISE_ADDR environment variable manually." >&2
80+
echo "Example: export ADVERTISE_ADDR=<your-server-ip>" >&2
81+
exit 1
82+
fi
83+
84+
echo "$ip"
5785
}
5886

5987
advertise_addr="${ADVERTISE_ADDR:-$(get_ip)}"
88+
echo "Using advertise address: $advertise_addr"
6089

6190
docker swarm init --advertise-addr $advertise_addr
6291

0 commit comments

Comments
 (0)