Skip to content

Commit e8d4aae

Browse files
authored
feat: add DNS pre-flight check to verify Docker connectivity before s… (#398)
* feat: add DNS pre-flight check to verify Docker connectivity before startup * feat: implement exponential backoff and improved status reporting for Docker DNS pre-flight checks
1 parent 4652d00 commit e8d4aae

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

scripts/start

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,45 @@ if [ "$EUID" -eq 0 ]
1919
exit 1
2020
fi
2121

22+
# ── DNS Pre-flight Check ─────────────────────────────────────────────
23+
YELLOW=$'\033[0;33m'
24+
BOLD_YELLOW=$'\033[1;33m'
25+
NC=$'\033[0m'
26+
DNS_TEST_URL="https://dl-cdn.alpinelinux.org"
27+
DNS_MAX_RETRIES=3
28+
DNS_OK=false
29+
BACKOFF=2
30+
31+
echo "Checking Docker DNS connectivity..."
32+
for i in $(seq 1 $DNS_MAX_RETRIES); do
33+
printf " [Attempt $i/$DNS_MAX_RETRIES] Testing resolution... "
34+
if docker run --rm alpine wget --spider --timeout=5 "$DNS_TEST_URL" > /dev/null 2>&1; then
35+
echo "Success"
36+
DNS_OK=true
37+
break
38+
else
39+
echo "Failed"
40+
fi
41+
[ "$i" -lt "$DNS_MAX_RETRIES" ] && sleep $BACKOFF && BACKOFF=$((BACKOFF * 2))
42+
done
43+
44+
if [ "$DNS_OK" = false ]; then
45+
cat <<EOF >&2
46+
47+
${BOLD_YELLOW} WARNING: Docker DNS resolution failed after $DNS_MAX_RETRIES attempts.${NC}
48+
${YELLOW} Containers cannot resolve external domains (e.g. dl-cdn.alpinelinux.org).
49+
This is commonly caused by a DNS bridge conflict with systemd-resolved.
50+
51+
Suggested fixes:
52+
1. Add DNS to /etc/docker/daemon.json:
53+
{ "dns": ["8.8.8.8", "8.8.4.4"] }
54+
2. Then run sudo systemctl restart docker
55+
56+
The build will continue, but may fail during package installation.${NC}
57+
58+
EOF
59+
fi
60+
2261
if [[ ! -d "${NOSTR_CONFIG_DIR}" ]]; then
2362
echo "Creating folder ${NOSTR_CONFIG_DIR}"
2463
mkdir -p "${NOSTR_CONFIG_DIR}"

0 commit comments

Comments
 (0)