call bitcoind rpc api over docker

505 Views Asked by At

I started my node container with this flags:

daemon=1
printtoconsole=1
testnet=1
rpcport=9332
rpcallowip=0.0.0.0/0
rpcuser=user
rpcpassword=password
rpcbind=0.0.0.0
server=1

I opened port in my docker-compose :

node:
    image: bitcoin-sv
    container_name: 'node'
    restart: always
    ports:
      - '9332:9332'

I can call methods from bitcoin-cli in my container

docker exec -it node bash
root@9196d074e4d8:/opt/bitcoin-sv# ./bitcoin-cli getinfo

But I cannot call it from curl

curl --user user --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo, "params": ["", 0.1, "donation", "seans outpost"] }' -H 'content-type: text/plain;' http://127.0.0.1:9332
Enter host password for user 'user':
curl: (52) Empty reply from server

How can i call it from curl? Maybe i have to call to cli?

1

There are 1 best solutions below

0
On

not sure what can be your issue, but the first approach would be do the curl inside the container in order to verify that the HTTP interface is working properly. So you should try this:

docker exec -it node bash
root@9196d074e4d8:/opt/bitcoin-sv# curl --user user --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo, "params": ["", 0.1, "donation", "seans outpost"] }' -H 'content-type: text/plain;' localhost:9332

Once you are sure the interface is working inside the container, you can move forwred and try it from the host.