|
| 1 | +# Bitcoin Core Docker Container |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This repository contains a Dockerfile for building and running a Bitcoin Core node. The Docker image is built in two stages: one for compiling Bitcoin Core from |
| 6 | +source and another for creating the final runtime image with only the necessary binaries and dependencies. |
| 7 | + |
| 8 | +## Description |
| 9 | + |
| 10 | +### Stage 1: Build Bitcoin Core |
| 11 | + |
| 12 | +- **Base Image**: `debian:bullseye-slim` |
| 13 | +- **Dependencies Installed**: |
| 14 | + - `automake`, `autotools-dev`, `build-essential`, `git`, `libtool`, `pkg-config`, `python3-minimal` |
| 15 | + - Boost libraries (`libboost-system-dev`, `libboost-filesystem-dev`, `libboost-chrono-dev`, `libboost-program-options-dev`, `libboost-test-dev`, |
| 16 | +`libboost-thread-dev`) |
| 17 | + - OpenSSL and libevent development libraries |
| 18 | + - `libdb++-dev`, `bsdmainutils` |
| 19 | +- **Build Process**: |
| 20 | + - Clones the Bitcoin Core repository (`v25.1`). |
| 21 | + - Configures, builds, and strips the `bitcoin-cli` binary. |
| 22 | + |
| 23 | +### Stage 2: Final Image |
| 24 | + |
| 25 | +- **Base Image**: `debian:bullseye-slim` |
| 26 | +- **Dependencies Installed**: |
| 27 | + - Boost runtime libraries |
| 28 | + - OpenSSL and libevent runtime libraries |
| 29 | + - `iproute2`, `iptables` |
| 30 | +- **Binary Copies**: |
| 31 | + - `bitcoind` and `bitcoin-cli` from the builder stage. |
| 32 | +- **Volume**: |
| 33 | + - `/bitcoin` for data storage. |
| 34 | +- **Ports Exposed**: |
| 35 | + - `8332` (RPC) |
| 36 | + - `8333` (P2P) |
| 37 | +- **Entry Point**: |
| 38 | + - Runs `bitcoind` with default configuration options. |
| 39 | + |
| 40 | +## How to Build the Image |
| 41 | + |
| 42 | +To build the Docker image, navigate to the directory containing the `Dockerfile` and run the following command: |
| 43 | + |
| 44 | +```sh |
| 45 | +docker build -t bitcoin-core:v25.1 . |
| 46 | +``` |
| 47 | + |
| 48 | +This will create a Docker image tagged as `bitcoin-core:v25.1`. |
| 49 | + |
| 50 | +## How to Run the Container |
| 51 | + |
| 52 | +### Basic Usage |
| 53 | + |
| 54 | +To run a Bitcoin Core node, use the following command: |
| 55 | + |
| 56 | +```sh |
| 57 | +docker run -d --name bitcoin-node -v bitcoin-data:/bitcoin -p 8332:8332 -p 8333:8333 bitcoin-core:v25.1 |
| 58 | +``` |
| 59 | + |
| 60 | +- `-d`: Runs the container in detached mode. |
| 61 | +- `--name bitcoin-node`: Assigns a name to the container. |
| 62 | +- `-v bitcoin-data:/bitcoin`: Mounts a Docker volume named `bitcoin-data` to `/bitcoin` inside the container. |
| 63 | +- `-p 8332:8332 -p 8333:8333`: Exposes ports 8332 and 8333. |
| 64 | + |
| 65 | +### Custom Configuration |
| 66 | + |
| 67 | +You can provide a custom configuration file (`bitcoin.conf`) by mounting it into the container: |
| 68 | + |
| 69 | +1. Create a `bitcoin.conf` file on your host machine. |
| 70 | +2. Mount this file into the container using the `-v` option. |
| 71 | + |
| 72 | +Example: |
| 73 | + |
| 74 | +```sh |
| 75 | +docker run -d --name bitcoin-node -v bitcoin-data:/bitcoin -v /path/to/bitcoin.conf:/bitcoin/bitcoin.conf -p 8332:8332 -p 8333:8333 bitcoin-core:v25.1 |
| 76 | +``` |
| 77 | + |
| 78 | +### Using RPC |
| 79 | + |
| 80 | +To interact with the Bitcoin Core node via RPC, you can use `bitcoin-cli` from another container or host machine. |
| 81 | + |
| 82 | +Example: |
| 83 | + |
| 84 | +```sh |
| 85 | +docker exec -it bitcoin-node bitcoin-cli getblockcount |
| 86 | +``` |
| 87 | + |
| 88 | +## Example Configuration File (`bitcoin.conf`) |
| 89 | + |
| 90 | +Here is an example of a basic `bitcoin.conf` file: |
| 91 | + |
| 92 | +```ini |
| 93 | +rpcuser=your_rpc_user |
| 94 | +rpcpassword=your_rpc_password |
| 95 | +rpcallowip=0.0.0.0/0 |
| 96 | +txindex=1 |
| 97 | +server=1 |
| 98 | +daemon=0 |
| 99 | +``` |
| 100 | + |
| 101 | +**Note**: Adjust the `rpcuser` and `rpcpassword` to secure your node. |
| 102 | + |
| 103 | +## Conclusion |
| 104 | + |
| 105 | +This Docker setup provides a convenient way to run a Bitcoin Core node in an isolated environment, making it easy to manage and scale. For more advanced |
| 106 | +configurations, refer to the [Bitcoin Core documentation](https://bitcoin.org/en/full-node). |
0 commit comments