Skip to content

Instantly share code, notes, and snippets.

@monadplus
Last active October 1, 2021 15:44
Show Gist options
  • Save monadplus/0f5de13814fe29c1305d3841be51d317 to your computer and use it in GitHub Desktop.
Save monadplus/0f5de13814fe29c1305d3841be51d317 to your computer and use it in GitHub Desktop.
Bitcoin Core: docker-compose

Create file docker-compose.yml (fix the parameters to your configuration):

version: "3.9"
services:
  bitcoin-core:
    container_name: bitcoin-server
    image: ruimarinho/bitcoin-core
    command:
      -printtoconsole
      -testnet=1
      -rpcallowip=0.0.0.0/0
      -rpcbind=0.0.0.0
      -rpcuser=rpcuser
      -rpcpassword=rpcpassword
      # -wallet=arnau
    ports:
      - "8332:8332" # rpc
      - "8333:8333"
      - "18332:18332" # rpc testnet
      - "18333:18333"
    volumes:
      - /data/.bitcoin:/home/bitcoin/.bitcoin

Then run:

docker-compose up &

Check the first lines to see that everything is OK.

To test everything is working:

docker exec --user bitcoin bitcoin-server bitcoin-cli \
  -testnet \
  -rpcuser=rpcuser \
  -rpcpassword=rpcpassword \
  getmininginfo

I also prepared a python script to test the RPC call. First, you need to install python and pip install python-bitcoinrpc and then copy this to a file called test.py

#!/usr/bin/env python
# -*- coding: utf8 -*-

from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException

rpc_user = "rpcuser"
rpc_password = "rpcpassword"
rpc_connection = AuthServiceProxy("http://%s:%[email protected]:18332"%(rpc_user, rpc_password))
best_block_hash = rpc_connection.getbestblockhash()
print(rpc_connection.getblock(best_block_hash))

And then chmod +x test.py and ./test.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment