-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathrun-ipfs.sh
More file actions
executable file
·44 lines (36 loc) · 1.15 KB
/
run-ipfs.sh
File metadata and controls
executable file
·44 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
set -euo pipefail
NAME="ipfs-node"
IMAGE="ipfs/kubo:latest"
DATA_DIR="${HOME}/ipfs-data"
API_PORT=5001 # HTTP API
GATEWAY_PORT=8080 # Gateway
SWARM_PORT=4001 # Libp2p swarm (TCP)
echo "▶︎ Starting IPFS daemon in Docker…"
# Create data directory if it doesn't exist
mkdir -p "${DATA_DIR}"
# Stop & remove any existing container with the same name
if docker ps -a --format '{{.Names}}' | grep -q "^${NAME}$"; then
echo "⏹ Removing existing container '${NAME}'…"
docker rm -f "${NAME}" >/dev/null
fi
# Launch the container detached
docker run -d --name "${NAME}" \
-v "${DATA_DIR}:/data/ipfs" \
-p "${SWARM_PORT}:4001" \
-p "${API_PORT}:5001" \
-p "${GATEWAY_PORT}:8080" \
"${IMAGE}" daemon >/dev/null
echo "⏳ Waiting for API to respond on :${API_PORT}…"
for i in {1..20}; do
if curl -fsS "http://127.0.0.1:${API_PORT}/api/v0/version" >/dev/null 2>&1; then
echo "✅ IPFS is up!"
echo "API: http://127.0.0.1:${API_PORT}"
echo "Gateway: http://127.0.0.1:${GATEWAY_PORT}"
exit 0
fi
sleep 1
done
echo "❌ IPFS API did not respond in time." >&2
docker logs --tail=100 "${NAME}" >&2
exit 1