Intro
Bitcoin is a decentralized digital currency that enables peer-to-peer transactions without the need for a central authority. It’s possible to participate to the network by installing a Bitcoin node.
A node ensures you have full control over your transactions, don’t rely on other entity, and directly participates in the Bitcoin network’s security and decentralization. It empowers you to verify transactions independently, enhancing your privacy and trust in the system.
Don’t trust, verify…
This guide will walk you through the process of installing a Bitcoin node and Electrs using Docker. By leveraging Docker, you can streamline the deployment and management of these services. Whether you’re a developer or an enthusiast, this step-by-step tutorial will simplify your setup process. Let’s dive into creating a robust and efficient Bitcoin node infrastructure.
Prerequisite
Before we start, ensure you have the following prerequisites:
- A server or machine with Docker installed.
- Basic understanding of Docker concepts such as containers, images, and volumes.
- Docker Compose.
Bitcoin
Configuration
To facilitate integration with other services, create a docker network using the command:
Create a bitcoin
folder and add the docker-compose.yml
file with the content below:
Add the ./data/bitcoin.conf
file with the following content:
You can generate the <user>
and <password>
data using the website https://jlopp.github.io/bitcoin-core-rpc-auth-generator/. For example for the user user
and password password
, the result will be rpcauth=user:a25ea0ca3f3d8ab20c3dce3959223427$05533202f12c57937a438c329fce23f9d2aff46b66db0d0d5ced785b4e598414
.
You can now start the bitcoin daemon using the command:
Check the status using the command:
docker exec -it bitcoind bitcoin-cli -getinfo
The result should be something like:
Chain: main
Blocks: 0
Headers: 34041
Verification progress: ▒░░░░░░░░░░░░░░░░░░░░ 0.0000%
Difficulty: 1
Network: in 0, out 7, total 7
Version: 250000
Time offset (s): 0
Proxies: n/a
Min tx relay fee rate (BTC/kvB): 0.00001000
Warnings: (none)
Tor proxy
Connecting a Bitcoin node to the Tor network enhances privacy by hiding the node’s public IP, allowing anonymity. In certain countries, using the Tor network also protects against censorship.
To allow the bitcoin node to connect to other peers using the Tor network, we will create a proxy service in the docker-compose.yml
Edit the file as following:
Note
Here, we use another network,
internal
, to ensure only the Bitcoin service can access the Tor proxy. Since the Bitcoin configuration requires an IP address, it is more convenient to set a static IP for the internal network.
Generate a Tor control password using the command:
The command should output something like (generated from password
string):
Then, create the Tor configuration file tor/config/torrc
:
HardwareAccel 1
Log notice stdout
DNSPort 10.254.0.2:8853
SocksPort 10.254.0.2:9050
ControlPort 10.254.0.2:9051
DataDirectory /var/lib/tor
HashedControlPassword <generated_password>
You can now verify that the Tor service works correctly by using the command:
docker compose up tor
Note
If you encounter a warning saying
[warn] /var/lib/tor is not owned by this user (tor, 100) but by root (0). Perhaps you are running Tor as the wrong user?
, you can resolve it by running the commandsudo chown -R 100:100 ./tor/data
to set the correct permissions for thetor
user in the./tor/data
folder.
Now, start all the services using:
Verify that bitcoin node is using tor network:
The result should be something like:
Electrs
Introduction
Electrs (Electrum Rust Server) is a lightweight, fast, and efficient Electrum server implementation in Rust. It is designed to run alongside a Bitcoin full node, enabling users to self-host their own Electrum server with minimal additional hardware requirements beyond those needed for the full node.
An Electrum server continuously indexes the Bitcoin blockchain, enabling users to efficiently track their wallets. Numerous wallets are compatible with an Electrum server, and by installing one on your own machine, you eliminate the need to rely on external servers for your data. This setup provides you with full control over your wallet information and enhances your privacy.
Configuration
Note
Since there is no official Electrs Docker image available, we will create our own.
Create a folder electrs
and a docker-compose.yml
file with the content below:
And a Dockerfile
:
You can now build the docker image using
Create the config file config/config.toml
with the following content:
And now you can start the container bu running:
Conclusion
With this configuration, you now have a fully functioning Bitcoin node with an Electrum server alongside it, enabling you to perform secure and efficient transactions, manage your wallet, and serve lightweight clients by providing them with fast and reliable access to the Bitcoin blockchain.
Resources
- Photo by Shubham Dhage on Unsplash
bitcoin
Github: https://github.com/bitcoin/bitcoinbitcoin
Docker image: https://github.com/lncm/docker-bitcoindelectrs
Github: https://github.com/romanz/electrstor
Docker image: https://github.com/dockur/tor