【发布时间】:2014-09-26 19:18:29
【问题描述】:
我正在测试一些与比特币相关的代码,为了测试它已经在 docker 容器中安装了 bitcoin-testnet-box。
它运行良好,并且在容器内我可以执行命令并查看结果。
Dockerfile 是exposing port 19001,我将其映射到端口49155 作为bitcond 实例之一的RPC 端口,我正在尝试使用node-bitcoin 与其通信。
我写了一个简单的测试,目的只是为了得到当前的难度。
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();
});
});
});
这失败了(请参阅下面的更新)并出现错误:
{ [错误:连接 ECONNREFUSED] 代码:'ECONNREFUSED', 错误号:'ECONNREFUSED', 系统调用:“连接”}
快速浏览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”,但结果相同。
显然我错过了一些简单的事情,因为 node-bitcoin tests 并没有真正做任何不同的事情。
用于运行bitcoin-testnet-box的命令是
docker run -ti --name bitcoind -P -p 49155:19001 freewil/bitcoin-testnet-box
我可能做错了什么?
更新
我按照下面的建议更改了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 运行 docker,所以我指的 IP 号是我运行 docker ip 时显示的 IP,而不是我的 Mac 本身的 IP。我在我的 Mac 上使用 NodeJS 运行测试,而不是在 boot2docker VM 或实际的 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 文件中的内容对我的用户名和密码进行了三次检查。
根据下面 Chris McKinnel 的建议,我在 docker 容器中运行了 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 文件中。唉,还是没有区别。
终于找到解决方案了
再次感谢 Chris McKinnel 下面的设置 rpcallowip=* 解决了这个问题。当然,这提出了一个全新的问题,但当我遇到它时,我会烧掉那座桥。现在我可以非常愉快地测试我的比特币流程了。
【问题讨论】:
-
您是尝试从 VM 内部还是从 VM 外部连接到 docker 客户端?
-
我正在尝试从 VM 外部连接
标签: node.js docker bitcoin bitcoind bitcoin-testnet