Hyperledger-fabric not working with docker swarm

0 votes

I'm using the Fabric 1.1 alpha release and trying to set it up using docker swarm. I'm using docker compose files with docker stack to deploy the containers. The issue is that my chaincode listening port which is 7052 is hardcoded somewhere in the peer container and is not listening on docker swarm.

The same compose file with minor changes works if I don't use docker swarm. I'm not sure if it's something wrong with the peer itself or with docker-swarm. This is from my peer container, which clearly is not allowing any connections on 7052 port although it's listening on port 7052:

root@71c1b8f22052:/opt/gopath/src/github.com/hyperledger/fabric/peer# telnet 10.0.0.6 7051
Trying 10.0.0.6...
Connected to 10.0.0.6.
Escape character is '^]'.
^CConnection closed by foreign host.
root@71c1b8f22052:/opt/gopath/src/github.com/hyperledger/fabric/peer# telnet 10.0.0.6 7052
Trying 10.0.0.6...
telnet: Unable to connect to remote host: Connection refused
root@71c1b8f22052:/opt/gopath/src/github.com/hyperledger/fabric/peer# telnet 10.0.0.6 7053
Trying 10.0.0.6...
Connected to 10.0.0.6.
Escape character is '^]'.
^CConnection closed by foreign host.

I'm getting this in my chaincode container logs when I 'm instantiating the chaincode.

2018-02-06 09:45:11.886 UTC [bccsp] initBCCSP -> DEBU 001 Initialize BCCSP [SW]
2018-02-06 09:45:11.906 UTC [grpc] Printf -> DEBU 002 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: Error while dialing dial tcp 10.0.0.10:7052: getsockopt: connection refused"; Reconnecting to {peer0.org1.example.com:7052 <nil>}
2018-02-06 09:45:12.905 UTC [grpc] Printf -> DEBU 003 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: Error while dialing dial tcp 10.0.0.10:7052: getsockopt: connection refused"; Reconnecting to {peer0.org1.example.com:7052 <nil>}
2018-02-06 09:45:14.612 UTC [grpc] Printf -> DEBU 004 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: Error while dialing dial tcp 10.0.0.10:7052: getsockopt: connection refused"; Reconnecting to {peer0.org1.example.com:7052 <nil>}
2018-02-06 09:45:14.904 UTC [shim] userChaincodeStreamGetter -> ERRO 005 context deadline exceeded
error trying to connect to local peer
github.com/hyperledger/fabric/core/chaincode/shim.userChaincodeStreamGetter
        /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/chaincode.go:111
github.com/hyperledger/fabric/core/chaincode/shim.Start
        /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/chaincode.go:150
main.main
        /chaincode/input/src/github.com/chaincode/alepomm/alepomm.go:355
runtime.main
        /opt/go/src/runtime/proc.go:195
runtime.goexit
        /opt/go/src/runtime/asm_amd64.s:2337
Error creating new Smart Contract: error trying to connect to local peer: context deadline exceeded

And here is my compose section for the peer.

peer0:
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # the following setting starts chaincode containers on the same
      # bridge network as the peers
      # https://docs.docker.com/compose/networking/
      - CORE_CHAINCODE_LOGGING_LEVEL=DEBUG
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb0:5984
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
#      - CORE_PEER_ADDRESSAUTODETECT=true
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
    ports:
     - 7051:7051
     - 7053:7053
    expose:
     - 7051
     - 7053
    command: peer node start
    depends_on:
      - couchdb0
    networks:
      fabric:
        aliases:
         - "peer0.org1.example.com"
    deploy:
      placement:
        constraints:
          - node.hostname == ip-172-31-22-132
Aug 17, 2018 in Blockchain by sabby
• 4,050 points
509 views

3 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+1 vote
Best answer

The issue is that the chaincode container is not being launched on the same network as my peer container and hence it was not able to connect to it. To fix it, do this:

CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052

Add to the env of your peer containers. Should work smoothly.

answered Aug 20, 2018 by Perry
• 16,450 points

selected May 2 by Omkar
–1 vote
Try adding     - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052   in each peer
answered Feb 14 by Blockchain Student
Hi. This is the same as the previous answer. I tried it, did not work. Any other solutions?
0 votes

Open a terminal, go to the directory where the hyperledger fabric files are stored. Then run the below command:

$ go build

Now, run your command again and see if it works

answered May 2 by Suman

I am getting the following error when I run go build:

command: 'go' not found

Hi @Raj, seems like go is not installed. First instal golang using the below command:

$ sudo apt-get update
$ sudo apt-get install golang

Then run 

$ go build

Related Questions In Blockchain

0 votes
1 answer

Not Able to register a user with Hyperledger-Fabric v1.1 preview

The error: "Certificate not found with AKI 'e729224e8b3f31784c8a93c5b8ef6f4c1c91d9e6e577c45c33163609fe40011' ...READ MORE

answered Jun 16, 2018 in Blockchain by charlie_brown
• 7,710 points
292 views
0 votes
1 answer

My first Hyperledger fabric network is not working

Delete as admin the channel-artifacts folder, down ...READ MORE

answered Aug 10, 2018 in Blockchain by Johnathon
• 9,050 points
46 views
0 votes
1 answer

Hyperledger Fabric: Not able to install docker

Clean up the invalid package repository: cd ../../etc/apt/sources.list.d sudo ...READ MORE

answered Nov 2, 2018 in Blockchain by Omkar
• 65,850 points
41 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,120 points
57 views
0 votes
1 answer

Hyperledger fabric: curl not working to invoke chaincode

Hyperledger Fabric does not offer a REST ...READ MORE

answered Oct 23, 2018 in Blockchain by Perry
• 16,450 points
120 views
0 votes
1 answer

Setting up Hyperledger Fabric Application with IBM Cloud.

You have to develop your "Client" application ...READ MORE

answered Nov 6, 2018 in Blockchain by Perry
• 16,450 points
91 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.