mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
docker: setup bitcoind docker image in the docker compose yaml file
This commit is contained in:
parent
2f04ce7c6e
commit
a7914af264
@ -13,6 +13,11 @@ docker | 1.13.0
|
||||
### Table of content
|
||||
* [Create lightning network cluster](#create-lightning-network-cluster)
|
||||
* [Connect to faucet lightning node](#connect-to-faucet-lightning-node)
|
||||
* [Building standalone docker images](#building-standalone-docker-images)
|
||||
* [Using bitcoind version](#using-bitcoind-version)
|
||||
* [Start Bitcoin Node with bitcoind using Docker Compose](#start-bitcoin-node-with-bitcoind-using-docker-compose)
|
||||
* [Generating RPCAUTH](#generating-rpcauth)
|
||||
* [Mining in regtest using bitcoin-cli](#mining-in-regtest-using-bitcoin-cli)
|
||||
* [Questions](#questions)
|
||||
|
||||
### Create lightning network cluster
|
||||
@ -327,10 +332,49 @@ Instructions on how to build standalone docker images (for development or
|
||||
production), outside of `docker-compose`, see the
|
||||
[docker docs](../docs/DOCKER.md).
|
||||
|
||||
### Using bitcoind version
|
||||
If you are using the bitcoind version of the compose file i.e `docker-compose-bitcoind.yml`, follow these additional instructions:
|
||||
|
||||
#### Start Bitcoin Node with bitcoind using Docker Compose
|
||||
To launch the Bitcoin node using bitcoind in the regtest network using Docker Compose, use the following command:
|
||||
```shell
|
||||
$ NETWORK="regtest" docker-compose -f docker-compose-bitcoind.yml up
|
||||
```
|
||||
|
||||
#### Generating RPCAUTH
|
||||
In bitcoind, the usage of `rpcuser` and `rpcpassword` for server-side authentication has been deprecated. To address this, we now use `rpcauth` instead. You can generate the necessary rpcauth credentials using the [rpcauth.py script](https://github.com/bitcoin/bitcoin/blob/master/share/rpcauth/rpcauth.py) from the Bitcoin Core repository.
|
||||
|
||||
Note: When using any RPC client, such as `lnd` or `bitcoin-cli`, It is crucial to either provide a clear text password with username or employ cookie authentication.
|
||||
|
||||
#### Mining in regtest using bitcoin-cli
|
||||
1. Log into the `lnd` container:
|
||||
```shell
|
||||
$ docker exec -it lnd bash
|
||||
```
|
||||
2. Generate a new backward compatible nested p2sh address:
|
||||
```shell
|
||||
lnd$ lncli --network=regtest newaddress np2wkh
|
||||
```
|
||||
3. Log into the `bitcoind` container:
|
||||
```shell
|
||||
$ docker exec -it bitcoind bash
|
||||
```
|
||||
4. Generate 101 blocks:
|
||||
```shell
|
||||
# Note: We need at least "100 >=" blocks because of coinbase block maturity.
|
||||
bitcoind$ bitcoin-cli -chain=regtest -rpcuser=devuser -rpcpassword=devpass generatetoaddress 101 2N1NQzFjCy1NnpAH3cT4h4GoByrAAkiH7zu
|
||||
```
|
||||
5. Check your lnd wallet balance in regtest network:
|
||||
```shell
|
||||
lnd$ lncli --network=regtest walletbalance
|
||||
```
|
||||
|
||||
Note: The address `2N1NQzFjCy1NnpAH3cT4h4GoByrAAkiH7zu` is just a random example. Feel free to use an address generated from your `lnd` wallet to send coins to yourself.
|
||||
|
||||
### Questions
|
||||
[![Irc](https://img.shields.io/badge/chat-on%20libera-brightgreen.svg)](https://web.libera.chat/#lnd)
|
||||
|
||||
* How to see `alice` | `bob` | `btcd` logs?
|
||||
* How to see `alice` | `bob` | `btcd` | `lnd` | `bitcoind` logs?
|
||||
```shell
|
||||
$ docker-compose logs <alice|bob|btcd>
|
||||
$ docker-compose logs <alice|bob|btcd|lnd|bitcoind>
|
||||
```
|
||||
|
7
docker/bitcoind/Dockerfile
Normal file
7
docker/bitcoind/Dockerfile
Normal file
@ -0,0 +1,7 @@
|
||||
FROM lightninglabs/bitcoin-core:${BITCOIN_VERSION:-25}
|
||||
|
||||
# Copy the start script into the container
|
||||
COPY start-bitcoind.sh .
|
||||
|
||||
# Set execute permissions for the script
|
||||
RUN chmod +x ./start-bitcoind.sh
|
75
docker/bitcoind/start-bitcoind.sh
Executable file
75
docker/bitcoind/start-bitcoind.sh
Executable file
@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# exit from script if error was raised.
|
||||
set -e
|
||||
|
||||
# error function is used within a bash function in order to send the error
|
||||
# message directly to the stderr output and exit.
|
||||
error() {
|
||||
echo "$1" > /dev/stderr
|
||||
exit 0
|
||||
}
|
||||
|
||||
# return is used within the bash function in order to return the value.
|
||||
return() {
|
||||
echo "$1"
|
||||
}
|
||||
|
||||
# set_default function gives the ability to move the setting of default
|
||||
# env variable from docker file to the script thereby giving the ability to the
|
||||
# user to override it during container start.
|
||||
set_default() {
|
||||
# docker initialized env variables with blank string and we can't just
|
||||
# use -z flag as usually.
|
||||
BLANK_STRING='""'
|
||||
|
||||
VARIABLE="$1"
|
||||
DEFAULT="$2"
|
||||
|
||||
if [[ -z "$VARIABLE" || "$VARIABLE" == "$BLANK_STRING" ]]; then
|
||||
|
||||
if [ -z "$DEFAULT" ]; then
|
||||
error "You should specify default variable"
|
||||
else
|
||||
VARIABLE="$DEFAULT"
|
||||
fi
|
||||
fi
|
||||
|
||||
return "$VARIABLE"
|
||||
}
|
||||
|
||||
# Set default variables if needed.
|
||||
|
||||
# This password is for testing and it is equivalent to `devpass`.
|
||||
# It is generated from (Note: It is fully deterministic, yet the random salt
|
||||
# generated by the script ensures that the resulting hash is always unique.):
|
||||
# https://github.com/bitcoin/bitcoin/blob/master/share/rpcauth/rpcauth.py
|
||||
DEFAULT_PASSWORD='22d3dd348a42d7f040487887b0ea6cc7$79ce831819539c78537884f85b65a09e15b079d79eb8f99447ea9b0a58fa66a6'
|
||||
|
||||
RPCAUTH=$(set_default "$RPCAUTH" "devuser:$DEFAULT_PASSWORD")
|
||||
NETWORK=$(set_default "$NETWORK" "regtest")
|
||||
DEBUG=$(set_default "$BITCOIND_DEBUG" "1")
|
||||
|
||||
PARAMS=""
|
||||
if [ "$NETWORK" != "mainnet" ]; then
|
||||
PARAMS="-$NETWORK"
|
||||
fi
|
||||
|
||||
PARAMS=$(echo $PARAMS \
|
||||
"-debug"="$DEBUG" \
|
||||
"-rpcauth"="$RPCAUTH" \
|
||||
"-datadir"="/data" \
|
||||
"-debuglogfile"="/data/debug.log" \
|
||||
"-rpcbind"="0.0.0.0" \
|
||||
"-rpcallowip"="0.0.0.0/0" \
|
||||
"-zmqpubrawblock"="tcp://0.0.0.0:28332" \
|
||||
"-zmqpubrawtx"="tcp://0.0.0.0:28333" \
|
||||
"-txindex"
|
||||
)
|
||||
|
||||
# Add user parameters to the command.
|
||||
PARAMS="$PARAMS $@"
|
||||
|
||||
# Print command and start bitcoin node.
|
||||
echo "Command: bitcoind $PARAMS"
|
||||
exec bitcoind $PARAMS
|
@ -10,14 +10,14 @@ error() {
|
||||
exit 0
|
||||
}
|
||||
|
||||
# return is used within bash function in order to return the value.
|
||||
# return is used within the bash function in order to return the value.
|
||||
return() {
|
||||
echo "$1"
|
||||
}
|
||||
|
||||
# set_default function gives the ability to move the setting of default
|
||||
# env variable from docker file to the script thereby giving the ability to the
|
||||
# user override it durin container start.
|
||||
# user to override it during container start.
|
||||
set_default() {
|
||||
# docker initialized env variables with blank string and we can't just
|
||||
# use -z flag as usually.
|
||||
@ -41,7 +41,7 @@ set_default() {
|
||||
# Set default variables if needed.
|
||||
RPCUSER=$(set_default "$RPCUSER" "devuser")
|
||||
RPCPASS=$(set_default "$RPCPASS" "devpass")
|
||||
DEBUG=$(set_default "$DEBUG" "info")
|
||||
DEBUG=$(set_default "$BTCD_DEBUG" "info")
|
||||
NETWORK=$(set_default "$NETWORK" "simnet")
|
||||
|
||||
PARAMS=""
|
||||
@ -66,7 +66,7 @@ if [[ -n "$MINING_ADDRESS" ]]; then
|
||||
PARAMS="$PARAMS --miningaddr=$MINING_ADDRESS"
|
||||
fi
|
||||
|
||||
# Add user parameters to command.
|
||||
# Add user parameters to the command.
|
||||
PARAMS="$PARAMS $@"
|
||||
|
||||
# Print command and start bitcoin node.
|
||||
|
47
docker/docker-compose-bitcoind.yml
Normal file
47
docker/docker-compose-bitcoind.yml
Normal file
@ -0,0 +1,47 @@
|
||||
version: '3'
|
||||
services:
|
||||
# lightninglabs/bitcoin-core is the base image for bitcoind.
|
||||
# The environment variables default values determined on stage of container
|
||||
# start within starting script.
|
||||
bitcoind:
|
||||
image: bitcoind
|
||||
container_name: bitcoind
|
||||
build:
|
||||
context: bitcoind/
|
||||
volumes:
|
||||
- bitcoin:/data
|
||||
environment:
|
||||
- RPCAUTH
|
||||
- NETWORK
|
||||
- BITCOIND_DEBUG
|
||||
entrypoint: ["./start-bitcoind.sh"]
|
||||
|
||||
lnd:
|
||||
image: lnd
|
||||
container_name: lnd
|
||||
build:
|
||||
context: ../
|
||||
dockerfile: dev.Dockerfile
|
||||
environment:
|
||||
- RPCUSER
|
||||
- RPCPASS
|
||||
- NETWORK
|
||||
- CHAIN
|
||||
- LND_DEBUG
|
||||
- BACKEND=bitcoind
|
||||
volumes:
|
||||
- lnd:/root/.lnd
|
||||
entrypoint: ["./start-lnd.sh"]
|
||||
links:
|
||||
- "bitcoind:blockchain"
|
||||
|
||||
volumes:
|
||||
# bitcoin volume is needed for maintaining blockchain persistence
|
||||
# during btcd container recreation.
|
||||
bitcoin:
|
||||
driver: local
|
||||
|
||||
# lnd volume is used for persisting lnd application data and chain state
|
||||
# during container lifecycle.
|
||||
lnd:
|
||||
driver: local
|
@ -15,7 +15,7 @@ services:
|
||||
- RPCUSER
|
||||
- RPCPASS
|
||||
- NETWORK
|
||||
- DEBUG
|
||||
- BTCD_DEBUG
|
||||
- MINING_ADDRESS
|
||||
entrypoint: ["./start-btcd.sh"]
|
||||
|
||||
@ -30,7 +30,8 @@ services:
|
||||
- RPCPASS
|
||||
- NETWORK
|
||||
- CHAIN
|
||||
- DEBUG
|
||||
- LND_DEBUG
|
||||
- BACKEND=btcd
|
||||
volumes:
|
||||
- shared:/rpc
|
||||
- lnd:/root/.lnd
|
||||
|
@ -38,15 +38,22 @@ set_default() {
|
||||
return "$VARIABLE"
|
||||
}
|
||||
|
||||
|
||||
# Set the default network and default RPC path (if any).
|
||||
DEFAULT_NETWORK="regtest"
|
||||
if [ "$BACKEND" == "btcd" ]; then
|
||||
DEFAULT_NETWORK="simnet"
|
||||
DEFAULT_RPCCRTPATH="/rpc/rpc.cert"
|
||||
fi
|
||||
|
||||
# Set default variables if needed.
|
||||
RPCCRTPATH=$(set_default "$RPCCRTPATH" "/rpc/rpc.cert")
|
||||
NETWORK=$(set_default "$NETWORK" "$DEFAULT_NETWORK")
|
||||
RPCCRTPATH=$(set_default "$RPCCRTPATH" "$DEFAULT_RPCCRTPATH")
|
||||
RPCHOST=$(set_default "$RPCHOST" "blockchain")
|
||||
RPCUSER=$(set_default "$RPCUSER" "devuser")
|
||||
RPCPASS=$(set_default "$RPCPASS" "devpass")
|
||||
DEBUG=$(set_default "$DEBUG" "debug")
|
||||
NETWORK=$(set_default "$NETWORK" "simnet")
|
||||
DEBUG=$(set_default "$LND_DEBUG" "debug")
|
||||
CHAIN=$(set_default "$CHAIN" "bitcoin")
|
||||
BACKEND="btcd"
|
||||
HOSTNAME=$(hostname)
|
||||
|
||||
# CAUTION: DO NOT use the --noseedback for production/mainnet setups, ever!
|
||||
@ -54,16 +61,36 @@ HOSTNAME=$(hostname)
|
||||
# address that is reachable on the internal network. If you do this outside of
|
||||
# docker, this might be a security concern!
|
||||
|
||||
exec lnd \
|
||||
--noseedbackup \
|
||||
"--$CHAIN.active" \
|
||||
"--$CHAIN.$NETWORK" \
|
||||
"--$CHAIN.node"="$BACKEND" \
|
||||
"--$BACKEND.rpccert"="$RPCCRTPATH" \
|
||||
"--$BACKEND.rpchost"="$RPCHOST" \
|
||||
"--$BACKEND.rpcuser"="$RPCUSER" \
|
||||
"--$BACKEND.rpcpass"="$RPCPASS" \
|
||||
"--rpclisten=$HOSTNAME:10009" \
|
||||
"--rpclisten=localhost:10009" \
|
||||
--debuglevel="$DEBUG" \
|
||||
"$@"
|
||||
if [ "$BACKEND" == "bitcoind" ]; then
|
||||
exec lnd \
|
||||
--noseedbackup \
|
||||
"--$CHAIN.active" \
|
||||
"--$CHAIN.$NETWORK" \
|
||||
"--$CHAIN.node"="$BACKEND" \
|
||||
"--$BACKEND.rpchost"="$RPCHOST" \
|
||||
"--$BACKEND.rpcuser"="$RPCUSER" \
|
||||
"--$BACKEND.rpcpass"="$RPCPASS" \
|
||||
"--$BACKEND.zmqpubrawblock"="tcp://$RPCHOST:28332" \
|
||||
"--$BACKEND.zmqpubrawtx"="tcp://$RPCHOST:28333" \
|
||||
"--rpclisten=$HOSTNAME:10009" \
|
||||
"--rpclisten=localhost:10009" \
|
||||
--debuglevel="$DEBUG" \
|
||||
"$@"
|
||||
elif [ "$BACKEND" == "btcd" ]; then
|
||||
exec lnd \
|
||||
--noseedbackup \
|
||||
"--$CHAIN.active" \
|
||||
"--$CHAIN.$NETWORK" \
|
||||
"--$CHAIN.node"="$BACKEND" \
|
||||
"--$BACKEND.rpccert"="$RPCCRTPATH" \
|
||||
"--$BACKEND.rpchost"="$RPCHOST" \
|
||||
"--$BACKEND.rpcuser"="$RPCUSER" \
|
||||
"--$BACKEND.rpcpass"="$RPCPASS" \
|
||||
"--rpclisten=$HOSTNAME:10009" \
|
||||
"--rpclisten=localhost:10009" \
|
||||
--debuglevel="$DEBUG" \
|
||||
"$@"
|
||||
else
|
||||
echo "Unknown backend: $BACKEND"
|
||||
exit 1
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user