Vaibhav
Vaibhav

Reputation: 83

How to map hyperledger fabric peers (2nd, 3rd , 4th) with ports for REST communication

I have hyperledger fabric 0.6 env setup on Windows 7 64bit OS using docker-Toolbox and I am using REST API client to trigger requests. Following is my four-peer-ca.yaml docker compose file:-

version: "2"
services: baseimage: image: hyperledger/fabric-baseimage:latest

membersrvc:
  image: hyperledger/fabric-membersrvc

  ports:
    - "7054:7054"

  command: membersrvc

  environment:

    - MEMBERSRVC_CA_LOGGING_SERVER=INFO
    - MEMBERSRVC_CA_LOGGING_CA=INFO
    - MEMBERSRVC_CA_LOGGING_ECA=INFO
    - MEMBERSRVC_CA_LOGGING_ECAP=INFO
    - MEMBERSRVC_CA_LOGGING_ECAA=INFO
    - MEMBERSRVC_CA_LOGGING_ACA=INFO
    - MEMBERSRVC_CA_LOGGING_ACAP=INFO
    - MEMBERSRVC_CA_LOGGING_TCA=INFO
    - MEMBERSRVC_CA_LOGGING_TCAP=INFO
    - MEMBERSRVC_CA_LOGGING_TCAA=INFO
    - MEMBERSRVC_CA_LOGGING_TLSCA=INFO

vp0:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "7050:7050"
    - "7051:7051"
    - "7053:7053"

  environment:
    - CORE_PEER_ID=vp0
    - CORE_SECURITY_ENROLLID=test_vp0
    - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4

  command: sh -c "sleep 10; peer node start"
  links: - membersrvc

vp1:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "8050:7050"
    - "8051:7051"
    - "8053:7053"
  environment:
    - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
    - CORE_PEER_ID=vp1
    - CORE_SECURITY_ENROLLID=test_vp1
    - CORE_SECURITY_ENROLLSECRET=5wgHK9qqYaPy
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4
  links: - membersrvc - vp0
  command: sh -c "sleep 10; peer node start"

vp2:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "9050:7050"
    - "9051:7051"
    - "9053:7053"
  environment:
    - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
    - CORE_PEER_ID=vp2
    - CORE_SECURITY_ENROLLID=test_vp2
    - CORE_SECURITY_ENROLLSECRET=vQelbRvja7cJ
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4
  links: - membersrvc - vp0
  command: sh -c "sleep 10; peer node start"

vp3:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "10050:7050"
    - "10051:7051"
    - "10053:7053"
  environment:
    - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
    - CORE_PEER_ID=vp3
    - CORE_SECURITY_ENROLLID=test_vp3
    - CORE_SECURITY_ENROLLSECRET=9LKqKH5peurL
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4
  links: - membersrvc - vp0
  command: sh -c "sleep 10; peer node start"**

//------------ using docker-compose up command, my server is up and all 4 peers are created successfully. in another docker terminal I executed following command which is also working fine:

CORE_CHAINCODE_ID_NAME=mycc006 CORE_PEER_ADDRESS=192.168.99.100:7051 ./chaincode_example02

Since I m using docker toolbox only 192.168.99.100 is a acceptable ip address for CORE_PEER_ADDRESS.

The REST API request are responsive to only - 192.168.99.100:7050/chaincode for all operations

You can see in the docker-compose file above that I have mapped vp1, vp2, vp3 with different ports and forwarded to vp0.

But when I try to use any other peer, for example vp1 using 192.168.99.100:8050/chaincode the request fails as there is no response from vp1,vp2,vp3 even though I have specifically mapped ports with these peers. Docker ps command shows memersrvc and all 4 peer containers running but ports are assigned only to vp0.

How do I map other peers vp1,vp2,vp3 with the ports inorder to access them via REST API ? Any help or guidance will be appreciated.

Thanks.

Upvotes: 1

Views: 1328

Answers (1)

david
david

Reputation: 101

your docker-compose file looks good beside some small issues in the mapping what I guess is related to the rendering on stackoverflow. Is the problem, that the REST endpoints are not working at all? Is for example http://localhost:10050/chain not accessible? If so, you might want to make sure that you are using the right images hyperledger/fabric-peer:x86_64-0.6.1-preview since that the docker-compose file works with 1.0-alpha images as well but there the REST API is missing. That slightly modified docker-compose file I attached bellow works out of the box. If that solves your problem you have to look into your docker images and see where the latest tag is pointing to.

version: "2"
services: # baseimage: image: hyperledger/fabric-baseimage:latest

  membersrvc:
    image: hyperledger/fabric-membersrvc

    ports:
      - "7054:7054"

    command: membersrvc

    environment:

      - MEMBERSRVC_CA_LOGGING_SERVER=INFO
      - MEMBERSRVC_CA_LOGGING_CA=INFO
      - MEMBERSRVC_CA_LOGGING_ECA=INFO
      - MEMBERSRVC_CA_LOGGING_ECAP=INFO
      - MEMBERSRVC_CA_LOGGING_ECAA=INFO
      - MEMBERSRVC_CA_LOGGING_ACA=INFO
      - MEMBERSRVC_CA_LOGGING_ACAP=INFO
      - MEMBERSRVC_CA_LOGGING_TCA=INFO
      - MEMBERSRVC_CA_LOGGING_TCAP=INFO
      - MEMBERSRVC_CA_LOGGING_TCAA=INFO
      - MEMBERSRVC_CA_LOGGING_TLSCA=INFO

  vp0:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes: 
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "7050:7050"
      - "7051:7051"
      - "7053:7053"

    environment:
      - CORE_PEER_ID=vp0
      - CORE_SECURITY_ENROLLID=test_vp0
      - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4

    command: sh -c "sleep 10; peer node start"
    links: 
      - membersrvc

  vp1:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes: 
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "8050:7050"
      - "8051:7051"
      - "8053:7053"
    environment:
      - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
      - CORE_PEER_ID=vp1
      - CORE_SECURITY_ENROLLID=test_vp1
      - CORE_SECURITY_ENROLLSECRET=5wgHK9qqYaPy
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4
    links: 
      - membersrvc 
      - vp0
    command: sh -c "sleep 10; peer node start"

  vp2:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes: 
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "9050:7050"
      - "9051:7051"
      - "9053:7053"
    environment:
      - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
      - CORE_PEER_ID=vp2
      - CORE_SECURITY_ENROLLID=test_vp2
      - CORE_SECURITY_ENROLLSECRET=vQelbRvja7cJ
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4
    links: 
      - membersrvc 
      - vp0
    command: sh -c "sleep 10; peer node start"

  vp3:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes: 
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "10050:7050"
      - "10051:7051"
      - "10053:7053"
    environment:
      - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
      - CORE_PEER_ID=vp3
      - CORE_SECURITY_ENROLLID=test_vp3
      - CORE_SECURITY_ENROLLSECRET=9LKqKH5peurL
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4
    links: 
      - membersrvc 
      - vp0
    command: sh -c "sleep 10; peer node start"

Upvotes: 2

Related Questions