How to connect to a Bitcoin testnet running in a docker container
I am testing some bitcoin related code and for testing it installed bitcoin-testnet-box in docker container.
It works fine and in the container I can execute commands and see the results.
Dockerfile showing port 19001 which I am mapping to port 49155
as RPC port for one of the instances bitcond
and I am trying to communicate using node-bitcoin .
I wrote a simple test that aims to simply get the current difficulty.
var bitcoin = require('bitcoin'),
client = new bitcoin.Client({
host: "192.168.59.103",
port: 49155,
user: "admin1",
pass: "123"
});
describe("Core Wallet Functions", function() {
it("can get the current bitcoin difficulty", function(done){
client.getDifficulty(function(err, difficulty){
console.log("got response", err, difficulty);
expect(err).to.equal(null);
expect(difficulty).to.equal(1);
done();
});
});
});
This is a bug (see update below) with the error:
{[Error: ECONNREFUSED connection] code: "ECONNREFUSED", errno: "ECONNREFUSED", syscall: 'connect'}
Quick view docker ps
shows
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8b04ed26d9e3 freewil/bitcoin-testnet-box:latest /bin/bash 3 hours ago Up 8 minutes 0.0.0.0:49155->19001/tcp, 0.0.0.0:49156->19011/tcp bitcoind
I tried changing host to "localhost" and "0.0.0.0" but got the same result.
Clearly I am missing something simple, since node-bitcoin tests doesn't actually do anything.
The command used to run bitcoin-testnet-box
was
docker run -ti --name bitcoind -P -p 49155:19001 freewil/bitcoin-testnet-box
What could I be doing wrong?
Update
I changed bitcoin.conf
as suggested below and now the error message is
[Error: Invalid params, response status code: 403]
Mine bitcoin.conf
looks like
# testnet-box functionality
testnet=1
dnsseed=0
upnp=0
rpcallowip=192.168.59.103
rpcallowip=192.168.1.4
rpcallowip=0.0.0.0
# listen on different ports than default testnet
port=19000
rpcport=19001
# always run a server, even with bitcoin-qt
server=1
# enable SSL for RPC server
#rpcssl=1
rpcuser=admin1
rpcpassword=123
another update
It is worth explaining what I run docker
on my Mac with boot2docker
, so the IP number I am referring to is the IP that is shown at startup docker ip
, not the IP of my Mac. I am running a test using NodeJS
on my Mac, not a VM boot or an actual Docker container. So, I tried to add rpcallowip=192.168.1.4
(where is 192.168.1.4
my Mac IP) to my files bitcoind.conf
too just in case. Alas, it didn't make any difference, I still get the answer { [Error: Invalid params, response status code: 403] code: -32602 }
.
I also triple-checked my username and password against what's in the bitcoin.conf file.
As suggested by Chris McKinnel below I have executed netstat -tunlp
in a docker container and it shows:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:19000 0.0.0.0:* LISTEN 65/bitcoind
tcp6 0 0 :::19000 :::* LISTEN 65/bitcoind
tcp6 0 0 :::19001 :::* LISTEN 65/bitcoind
tcp6 0 0 :::19011 :::* LISTEN 75/bitcoind
So I added rpcallowip=0.0.0.0
to my bitcoin.conf
file. Alas, there is still no difference.
finally a solution
Thanks again to Chris McKinnell below who rpcallowip=*
solved the problem. Of course this poses a whole new problem, but I will burn this bridge when I get to it. So far, I can check my bitcoin processes quite happily.
source to share
I think you need to add rpcallowip=192.168.59.103
to both of your files bitcoin.conf
for nodes. By default, bitcoind
will only listen for RPC connections to localhost (as per the docs ).
Once you have added your IP to the list of permissions, you can check if it works by running telnet 192.168.59.103 19001
.
To see a list of your PC's open ports (and where they accept connections from), run netstat -tunlp
.
source to share