如何连接到docker集装箱中运行的比特币testing网

我正在testing一些与比特币相关的代码,为了testing它在docker集装箱内安装了bitcoin-testnet-box 。

它运行良好,并且在容器内我可以执行命令并查看结果。

Dockerfile 公开端口19001 ,我将其映射到端口49155作为bitcond实例之一的RPC端口,我试图使用节点比特币与它进行通信。

我写了一个简单的testing,目的只是为了获得目前的困难。

 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(); }); }); }); 

这是失败的( 见下面的更新 )与错误:

{[Error:connect ECONNREFUSED] code:'ECONNREFUSED',errno:'ECONNREFUSED',syscall:'connect'}

快速浏览docker ps展示

 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 

我试图改变主机“localhost”和“0.0.0.0”,但得到了相同的结果。

显然,我错过了简单的事情,因为节点 – 比特币testing实际上并没有什么不同。

用来运行bitcoin-testnet-box的命令是

 docker run -ti --name bitcoind -P -p 49155:19001 freewil/bitcoin-testnet-box 

我可能会做错什么?

更新

我按照下面的build议更改了bitcoin.conf ,现在错误信息是

 [Error: Invalid params, response status code: 403] 

我的bitcoin.conf看起来像

 # 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 

另一个更新

值得说明的是,我在我的Mac上使用boot2docker运行boot2docker所以我所指的IP地址是在运行docker ip时显示的IP docker ip ,而不是我的Mac本身的IP地址。 我在我的Mac上使用NodeJS运行testing,而不是在boot2docker虚拟机或实际的Docker容器中。 所以,我已经尝试将rpcallowip=192.168.1.4 (其中192.168.1.4是我的Mac的IP)添加到我的bitcoind.conf文件中以防万一。 唉,这没有什么区别,我仍然得到{ [Error: Invalid params, response status code: 403] code: -32602 }响应。

我还对bitcoin.conf文件中的内容进行了三重检查。

Per Chris McKinnel的build议下面我已经在netstat -tunlp容器中运行了netstat -tunlp ,它显示:

 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 

所以我也将rpcallowip=0.0.0.0添加到我的bitcoin.conf文件中。 唉,仍然没有区别。

最后是解决scheme

再次感谢Chris McKinnel下面的设置rpcallowip=*解决了这个问题。 当然,这提出了一个全新的问题,但是当我接近它的时候,我会烧掉那座桥。 现在我可以很高兴地testing我的比特币进程。

我想你需要添加rpcallowip=192.168.59.103到你的两个bitcoin.conf文件的节点。 默认情况下bitcoind将只监听本地主机上的RPC连接(根据文档 )。

将IP添加到允许列表后,可以通过telnet 192.168.59.103 19001来检查是否工作正常。

要查看您的PC打开端口(以及从哪里接受连接)的列表,请执行netstat -tunlp

我只会改变

rpcallowip=192.168.*.*

这样至less在C级的范围内

Interesting Posts