0

I'm a student trying to learn something about blockchain with the hyperledger course from the linux foundation. I'm installing the sawtooth framework trough docker and I have some issues. I'm trying to check the connectivity from the host computer to the Docker container, running the following command:

curl http://localhost:8008/blocks

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

Someone can help me to open this connection docker and host machine? I'm using a virtual machine with ubuntu, thanks a lot in advance!

Here is the yaml file:

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 \
    \""
Carlos
  • 3
  • 3

3 Answers3

2

you should pass the port from local computer to Docker container.

more here

try to pass -p 8008:8008 as an argument when running the container

For example. docker run -d -p 8008:8008 my_image

Senior Pomidor
  • 1,823
  • 1
  • 14
  • 23
  • Sorry but I'm not explain it very well, the sequence of commands that I'm trying to use: 1- This command will download the Docker images that comprise the Hyperledger Sawtooth demo environment: $ docker-compose -f sawtooth-default.yaml up 2- Log into the client container by running the following command: $ docker exec -it sawtooth-shell-default bash 3- To check the connectivity from the host computer to the Docker container: $ curl http://localhost:8008/blocks Where I need to put the argument that you suggest me? Thanks again! – Carlos Aug 07 '18 at 10:05
  • add your sawtooth-default.yaml file to your question(add to edit). I think your yaml file missed the port or has an another port – Senior Pomidor Aug 07 '18 at 10:11
  • and no error from compose? I see one error here `rest- api:8008`. odd space – Senior Pomidor Aug 07 '18 at 10:36
  • The yaml file comes from this repository https://raw.githubusercontent.com/hyperledger/education/master/LFS171x/sawtooth-material/sawtooth-default.yaml I think that is ok because it comes from a official repository. There is no error here in my shell. Maybe is a problem with the ports in the virtual machine? I'm using ubuntu in a virtual box over widows 10 – Carlos Aug 07 '18 at 11:33
  • and where you called curl? from windows or ubuntu? – Senior Pomidor Aug 07 '18 at 11:55
  • see. in your link I see `rest-api:8008`. but you have a `rest- api:8008 ` – Senior Pomidor Aug 07 '18 at 13:24
1

If you are using virtual machine, then you need to open 8008 port from your virtual machine so that it can be accessible from Host machine.

but it also depends on which network your virtual machine has been spawned. Here is the sample Vagrant file for spawning your virtual machine and it will have 8008 port of virtual machine mapped to your host machine.

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  

Now, if you access localhost:8008, it will be redirected to virtualmachine 8008 port which in turn mapped to docker 8008 port. You can also do, curl http://192.168.1.15:8008 to access the sawtooth rest-api.

GraphicalDot
  • 2,644
  • 2
  • 28
  • 43
1

I had the same problem and I was able to resolve it by connecting to the ip address generated while running sawtooth (initial terminal).

In the first terminal when you force stop(or just stop) sawtooth such an image is displayed Data regarding the connection pool

So run sawtooth again and when checking connectivity in the host machine use

curl http://192.168.99.100:8008/blocks

i.e

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

Hope this helps!