Skip to content

Commit 8b1c029

Browse files
committed
Add check-docker-network.sh script for Docker network diagnostics and update docker-compose.yml with gateway IP verification comment
1 parent a28e161 commit 8b1c029

2 files changed

Lines changed: 98 additions & 5 deletions

File tree

check-docker-network.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
# Script to verify Docker network configuration for electrs
3+
4+
echo "=== DOCKER NETWORK DIAGNOSTIC ==="
5+
echo ""
6+
7+
# Check if electrs network exists
8+
echo "1. Checking electrs-network..."
9+
docker network inspect electrs-network > /dev/null 2>&1
10+
if [ $? -eq 0 ]; then
11+
echo " ✓ electrs-network exists"
12+
13+
# Get gateway IP
14+
GATEWAY_IP=$(docker network inspect electrs-network | grep -i gateway | head -1 | awk '{print $2}' | tr -d '",')
15+
echo " Gateway IP: $GATEWAY_IP"
16+
17+
# Check what's configured in docker-compose.yml
18+
CONFIGURED_IP=$(grep "daemon-rpc-addr" docker-compose.yml | grep -oP '\d+\.\d+\.\d+\.\d+' | head -1)
19+
echo " Configured IP in docker-compose.yml: $CONFIGURED_IP"
20+
21+
if [ "$GATEWAY_IP" != "$CONFIGURED_IP" ]; then
22+
echo " ⚠ WARNING: Gateway IP mismatch!"
23+
echo " The configured IP ($CONFIGURED_IP) doesn't match the actual gateway ($GATEWAY_IP)"
24+
echo " This will cause connection failures!"
25+
echo ""
26+
echo " Fix: Update docker-compose.yml:"
27+
echo " Change: --daemon-rpc-addr=$CONFIGURED_IP:8332"
28+
echo " To: --daemon-rpc-addr=$GATEWAY_IP:8332"
29+
else
30+
echo " ✓ Gateway IP matches configuration"
31+
fi
32+
else
33+
echo " ✗ electrs-network does not exist"
34+
echo " Run: docker-compose up -d (this will create the network)"
35+
fi
36+
37+
echo ""
38+
echo "2. Testing bitcoind connection from host..."
39+
BITCOIND_RESPONSE=$(curl -s --user bitcoinrpc:cab44cb7d0ee18fe1c556ae50bae373c8ea81212179c09cfbdee9425dfcbd516 --data-binary '{"jsonrpc":"1.0","id":"test","method":"getblockchaininfo","params":[]}' -H 'content-type: text/plain;' --max-time 5 http://localhost:8332/ 2>&1)
40+
if echo "$BITCOIND_RESPONSE" | grep -q "result"; then
41+
echo " ✓ Bitcoind RPC is accessible from host"
42+
else
43+
echo " ✗ Bitcoind RPC is NOT accessible from host"
44+
echo " Response: $BITCOIND_RESPONSE"
45+
fi
46+
47+
echo ""
48+
echo "3. Testing bitcoind connection from Docker network..."
49+
if [ ! -z "$GATEWAY_IP" ]; then
50+
DOCKER_TEST=$(docker run --rm --network electrs-network curlimages/curl:latest curl -s --max-time 5 --user bitcoinrpc:cab44cb7d0ee18fe1c556ae50bae373c8ea81212179c09cfbdee9425dfcbd516 --data-binary '{"jsonrpc":"1.0","id":"test","method":"getblockchaininfo","params":[]}' -H 'content-type: text/plain;' http://$GATEWAY_IP:8332/ 2>&1)
51+
if echo "$DOCKER_TEST" | grep -q "result"; then
52+
echo " ✓ Bitcoind RPC is accessible from Docker network at $GATEWAY_IP:8332"
53+
else
54+
echo " ✗ Bitcoind RPC is NOT accessible from Docker network at $GATEWAY_IP:8332"
55+
echo " This is the problem! Check bitcoind firewall/rpcallowip settings"
56+
fi
57+
fi
58+
59+
echo ""
60+
echo "4. Checking electrs container network..."
61+
ELECTRS_IP=$(docker inspect electrs --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 2>/dev/null)
62+
if [ ! -z "$ELECTRS_IP" ]; then
63+
echo " Electrs container IP: $ELECTRS_IP"
64+
echo " ✓ Electrs container is running"
65+
else
66+
echo " ✗ Electrs container is not running"
67+
fi
68+
69+
echo ""
70+
echo "5. Checking for connection issues..."
71+
CONNECTION_COUNT=$(ss -tnp | grep :8332 | grep ESTAB | wc -l)
72+
FIN_WAIT=$(ss -tnp | grep :8332 | grep FIN-WAIT | wc -l)
73+
echo " Established connections to bitcoind: $CONNECTION_COUNT"
74+
echo " Connections in FIN-WAIT state: $FIN_WAIT"
75+
if [ "$FIN_WAIT" -gt 10 ]; then
76+
echo " ⚠ WARNING: Many connections in FIN-WAIT state - connection cleanup issues"
77+
fi
78+
79+
echo ""
80+
echo "=== SUMMARY ==="
81+
if [ "$GATEWAY_IP" != "$CONFIGURED_IP" ] && [ ! -z "$GATEWAY_IP" ] && [ ! -z "$CONFIGURED_IP" ]; then
82+
echo "⚠ ACTION REQUIRED: Update docker-compose.yml with correct gateway IP: $GATEWAY_IP"
83+
echo ""
84+
echo "Run this command to fix:"
85+
echo "sed -i 's|--daemon-rpc-addr=$CONFIGURED_IP:8332|--daemon-rpc-addr=$GATEWAY_IP:8332|g' docker-compose.yml"
86+
else
87+
echo "✓ Network configuration looks correct"
88+
fi
89+

docker-compose.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ services:
2020
- "--db-dir=/data/db"
2121
- "--daemon-dir=/bitcoin"
2222
- "--blocks-dir=/bitcoin-blocks"
23+
# Verify gateway IP with: docker network inspect electrs-network | grep Gateway
2324
- "--daemon-rpc-addr=172.18.0.1:8332"
2425
- "--cookie=bitcoinrpc:PLACEHOLDER_PASSWORD"
2526
- "--http-addr=0.0.0.0:3000"
@@ -33,17 +34,20 @@ services:
3334
- "-vvv"
3435
- "--timestamp"
3536
healthcheck:
36-
test: ["CMD", "curl", "-f", "http://localhost:3000/api/blocks/tip/height"]
37-
interval: 30s
38-
timeout: 10s
39-
retries: 3
40-
start_period: 300s
37+
test: ["CMD", "curl", "-f", "--max-time", "30", "http://localhost:3000/api/blocks/tip/height"]
38+
interval: 60s
39+
timeout: 30s
40+
retries: 5
41+
start_period: 600s
4142
extra_hosts:
4243
- "host.docker.internal:host-gateway"
4344
ulimits:
4445
nofile:
4546
soft: 100000
4647
hard: 100000
48+
# Optional: Add memory limit to prevent OOM issues
49+
# mem_limit: 16g
50+
# mem_reservation: 8g
4751

4852
nginx:
4953
image: nginx:alpine

0 commit comments

Comments
 (0)