超级账本锯齿安装问题.主机和 docker 容器之间没有连接



我是一名学生,试图通过Linux基金会的Hyperledger课程学习区块链。我正在安装锯齿框架槽码头工人,我遇到了一些问题。我正在尝试检查从主机到 Docker 容器的连接,运行以下命令:

curl http://localhost:8008/blocks
curl: (7) Failed to connect to localhost port 8008: Connection refused

有人可以帮助我打开这个连接码头工人和主机吗?我正在使用带有 ubuntu 的虚拟机,提前非常感谢!

这是 yaml 文件:

version: "2.1"
services:
settings-tp:
image: hyperledger/sawtooth-settings-tp:1.0
container_name: sawtooth-settings-tp-default
depends_on:
  - validator
entrypoint: settings-tp -vv -C tcp://validator:4004
intkey-tp-python:
image: hyperledger/sawtooth-intkey-tp-python:1.0
container_name: sawtooth-intkey-tp-python-default
depends_on:
  - validator
entrypoint: intkey-tp-python -vv -C tcp://validator:4004
xo-tp-python:
image: hyperledger/sawtooth-xo-tp-python:1.0
container_name: sawtooth-xo-tp-python-default
depends_on:
  - validator
entrypoint: xo-tp-python -vv -C tcp://validator:4004
validator:
image: hyperledger/sawtooth-validator:1.0
container_name: sawtooth-validator-default
expose:
  - 4004
ports:
  - "4004:4004"
# start the validator with an empty genesis batch
entrypoint: "bash -c "
    sawadm keygen && 
    sawtooth keygen my_key && 
    sawset genesis -k /root/.sawtooth/keys/my_key.priv && 
    sawadm genesis config-genesis.batch && 
    sawtooth-validator -vv 
      --endpoint tcp://validator:8800 
      --bind component:tcp://eth0:4004 
      --bind network:tcp://eth0:8800 
    ""
 rest-api:
 image: hyperledger/sawtooth-rest-api:1.0
 container_name: sawtooth-rest-api-default
 ports:
  - "8008:8008"
 depends_on:
  - validator
 entrypoint: sawtooth-rest-api -C tcp://validator:4004 --bind rest- api:8008
shell:
image: hyperledger/sawtooth-all:1.0
container_name: sawtooth-shell-default
depends_on:
  - rest-api
entrypoint: "bash -c "
    sawtooth keygen && 
    tail -f /dev/null 
    ""

你应该将端口从本地计算机传递到Docker容器。

更多 这里

尝试在运行容器时将-p 8008:8008作为参数传递

例如。 docker run -d -p 8008:8008 my_image

如果您使用的是虚拟机,则需要从虚拟机打开 8008 端口,以便可以从主机访问它。

但这也取决于虚拟机生成的网络。下面是用于生成虚拟机的示例 Vagrant 文件,它将具有映射到主机的虚拟机的 8008 端口。

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "sawtoothprocessor", primary: true do |sawtoothprocessor|
    sawtoothprocessor.vm.box = "ubuntu/xenial64"
    sawtoothprocessor.vm.hostname ="sawtoothprocessor"
    sawtoothprocessor.vm.network :public_network, ip: "192.168.1.15"
    sawtoothprocessor.vm.network "forwarded_port", guest: 9001, host: 9001,
            auto_correct: true
    sawtoothprocessor.vm.network "forwarded_port", guest: 8000, host: 8000,
            auto_correct: true
    sawtoothprocessor.vm.network "forwarded_port", guest: 8008, host: 8008,
            auto_correct: true  

现在,如果您访问 localhost:8008,它将被重定向到虚拟机 8008 端口,该端口又映射到 docker 8008 端口。 你也可以做,卷曲 http://192.168.1.15:8008 访问锯齿休息 api。

我遇到了同样的问题,我能够通过连接到运行锯齿(初始终端(时生成的 IP 地址来解决它。

在第一个终端中,当您强制停止(或只是停止(锯齿时,会显示这样的图像 有关连接池的数据

因此,再次运行锯齿,并在检查主机中的连接时使用

curl http://192.168.99.100:8008/blocks

curl http://<your ip address>/blocks

希望这有帮助!

最新更新