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/.bitcoinThen 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 \
getmininginfoI 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.