Search code examples
node.jsdockerbitcoind

403 Forbidden from bitcoind -server run on docker


I'm using the new Docker-for-Mac to run the daemon like this:

$docker run -d --name bitcoind -e BITCOIN_DATA=/data \
    -v ${PWD}/bitcoind:/data -p 8332:8332 seegno/bitcoind:latest \
    -server -rpcuser=test -rpcpassword=nopass -rpcallowip=192.168.1.67 \
    -printtoconsole -debug=rpc

where the IP address I allow is my default:

$ ifconfig |grep inet |grep -v inet6
    inet 127.0.0.1 nitmask 0xff000000 
    inet 192.168.1.67 netmask 0xffffff00 broadcast 192.168.1.255

I then run my app:

var BTC = require('bitcoin-core');
var opts = { 
    host: 'localhost',
    port: 8332,
    username: 'test',
    password: 'nopass'
};
btc = new BTC(opts);
btc.getNewAddress().then(function(s) {
    console.log(s);
});

and get:

Unhandled rejection RpcError: 403 Forbidden at get (/Users/ekkis/Development/Test/www/node_modules/bitcoin-core/dist/src/parser.js:34:11) at Client.rpc (/Users/ekkis/Development/Test/www/node_modules/bitcoin-core/dist/src/parser.js:81:14) at Request.self.callback (/Users/ekkis/Development/Test/www/node_modules/request/request.js:200:22) at emitTwo (events.js:87:13) at Request.emit (events.js:172:7) at Request. (/Users/ekkis/Development/Test/www/node_modules/request/request.js:1067:10) at emitOne (events.js:82:20) at Request.emit (events.js:169:7) at IncomingMessage. (/Users/ekkis/Development/Test/www/node_modules/request/request.js:988:12) From previous event: at /Users/ekkis/Development/Test/www/node_modules/bitcoin-core/dist/src/index.js:163:21 From previous event: at Client.command (/Users/ekkis/Development/Test/www/node_modules/bitcoin-core/dist/src/index.js:152:34) at apply (/Users/ekkis/Development/Test/www/node_modules/lodash/lodash.js:409:27) at Client.wrapper [as getNewAddress] (/Users/ekkis/Development/Test/www/node_modules/lodash/lodash.js:4837:16) at Object. (/Users/ekkis/Development/Test/www/t:12:5) at Module._compile (module.js:425:26) at Object.Module._extensions..js (module.js:432:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:311:12) at Function.Module.runMain (module.js:457:10) at startup (node.js:136:18) at node.js:972:3

though I seem able to connect to the server:

$ telnet localhost 8332
Trying ::1...
Connected to localhost.
Escape character is '^]'.

it doesn't hang up on me with a connection error... what am I missing?

* edit I *

well... if I run the daemon with -logips and make my attempt I see:

2016-07-09 18:32:26 Received a POST request for / from 172.17.0.1:50262

instead of the IP address I expected. I gather it's the IP address of the VM that Docker runs, that somehow gets routed to the container. so now the question is: how do I discover that IP address from my node app so I can whitelist it?


Solution

  • and... (drumroll) the answer seems to be that I can pick it up from the docker inspect NetworkSettings.Gateway key. but... in fact, I can bake it into the CLI because for this image the gateway is always the same