首页 文章

Hyperledger锯齿安装问题 . 主机和docker容器之间没有连接

提问于
浏览
0

我是一名学生,试图通过linux基础的hyperledger课程学习区块链 . 我正在安装锯齿框架槽式码头,我有一些问题 . 我正在尝试检查从主机到Docker容器的连接,运行以下命令:

curl http://localhost:8008/blocks

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

有人可以帮我打开这个连接docker和主机吗?我正在使用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 \
    \""

2 回答

  • 1

    如果您使用的是虚拟机,则需要从虚拟机打开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,它将被重定向到virtualmachine 8008端口,该端口又映射到docker 8008端口 . 你也可以,curl http://192.168.1.15:8008访问sawtooth rest-api .

  • 2

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

    更多here

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

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

相关问题