Skip to content

jamsrworld/bitcoin-node-docker-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Bitcoin Full Node with Docker

This guide provides step-by-step instructions for setting up a Bitcoin full node using Docker, with optional snapshot integration to accelerate the initial blockchain synchronization.


📁 Directory Structure

BTC/
├── compose.yml
└── btc-data/
    └── bitcoin.conf

🛠️ Step-by-Step Setup

1. Create compose.yml in the root of the BTC directory:

# compose.yml
services:
  bitcoin-node:
    image: ruimarinho/bitcoin-core:latest
    container_name: bitcoin-node
    ports:
      - "8333:8333" # P2P port
      - "8332:8332" # RPC port
    volumes:
      - ./btc-data:/home/bitcoin/.bitcoin

2. Create bitcoin.conf inside the btc-data/ directory:

# bitcoin.conf

server=1
listen=1

rpcuser=admin
rpcpassword=yourStrongPassword
rpcallowip=0.0.0.0/0
rpcbind=0.0.0.0

# Optional settings:
# Uncomment to enable prune mode
#prune=550
#txindex=0

# Performance tuning
dbcache=4096  # Use 4 GB for caching (adjust based on RAM)

▶️ Docker Commands

Start the Bitcoin node:

docker compose up -d

Stop the node:

docker compose down

Restart the node:

docker compose down
docker compose up -d

View real-time logs:

docker compose logs -f

Check Blockchain Sync Status:

docker exec -it bitcoin-node bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo

Check Connected Peers:

docker exec -it bitcoin-node bitcoin-cli -datadir=/home/bitcoin/.bitcoin getconnectioncount

Watch Live Sync Progress (Optional):

watch -n 5 "docker exec -it bitcoin-node bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo"

This will refresh the blockchain sync info every 5 seconds. Press Ctrl+C to stop watching.

📦 Importing the Bitcoin Blockchain Snapshot (Optional)

To speed up the initial sync, you can use a trusted Bitcoin snapshot. There are two options:

🟢 Option 1: Full Node Snapshot

  1. Replace the blocks/ and chainstate/ folders inside btc-data/ with snapshot data. After that:

  2. Temporarily override the command in compose.yml by adding:

command: ["bitcoind", "-reindex-chainstate"] # 👈 Add temporarily
# compose.yml

services:
  bitcoin-node:
    image: ruimarinho/bitcoin-core:latest
    container_name: bitcoin-node
    command: ["bitcoind", "-reindex-chainstate"] # 👈 Add temporarily
    ports:
      - "8333:8333"
      - "8332:8332"
    volumes:
      - ./btc-data:/home/bitcoin/.bitcoin
  1. Run and monitor:
docker compose up -d
docker compose logs -f
  1. After reindex completes, remove the command line and restart:
docker compose down
docker compose up -d

🟡 Option 2: Pruned Node Snapshot (prune=550 or any > 0)

Replace the entire btc-data/ folder with the one from the snapshot source.

Ensure prune=550 (or your value) is set in bitcoin.conf.

✅ Do NOT use -reindex or -reindex-chainstate. That will delete pruned data and force full sync from 0.

Start the node normally:

docker compose up -d

✅ Optional: Add Makefile Commands for convenience

start:
	docker compose up -d

down:
	docker compose down

restart:
	docker compose down
	docker compose up -d

logs:
	docker compose logs -f

info:
	docker exec -it bitcoin-node bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo

peers:
	docker exec -it bitcoin-node bitcoin-cli -datadir=/home/bitcoin/.bitcoin getconnectioncount

After creating the Makefile, you can use:

make start
make logs
make info

About

Run a full Bitcoin Core node with Docker. Supports pruning, snapshots, and live monitoring.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published