Search code examples
dockerhyperledger-fabrichyperledgerdocker-swarm

Hyperledger Fabric - Join peer from another host


My setup is the following:

How I'm actually running the Fabric network:

  1. I'm generating the channel artifacts & crypto-config files the same on both hosts.
  2. Starting fabric on host 2 - with both peers, couchdbs and ca;
  3. Starting fabric on host 1;
  4. Generating a channel on host 1; joining peers from host 1 and updating anchor peer;
  5. When inspecting the overlay swarm network I'm able to see both peers and containers available for each host;

My problems appear when trying to make the peers from host 2 join the channel. I'm trying to add them to the channel through the cli on host 1.

But I'm receiving the following error:

Error: error getting endorser client for channel: endorser client failed to connect to peer0.sponsor.example.com:7051: failed to create new connection: context deadline exceeded

This is my docker-compose-cli.yaml for host 1:

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2'

volumes:
  orderer.example.com:
  peer0.manager.example.com:
  peer1.manager.example.com:
  peer0.sponsor.example.com:
  peer1.sponsor.example.com:

networks:
  example:

services:

  orderer.example.com:
    extends:
      file:   base/docker-compose-base-1.yaml
      service: orderer.example.com
    container_name: orderer.example.com
    networks:
      - example

  peer0.manager.example.com:
    container_name: peer0.manager.example.com
    extends:
      file:  base/docker-compose-base-1.yaml
      service: peer0.manager.example.com
    networks:
      - example

  peer1.manager.example.com:
    container_name: peer1.manager.example.com
    extends:
      file:  base/docker-compose-base-1.yaml
      service: peer1.manager.example.com
    networks:
      - example

  cli:
    container_name: cli
    image: hyperledger/fabric-tools:$IMAGE_TAG
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      #- CORE_LOGGING_LEVEL=DEBUG
      - CORE_LOGGING_LEVEL=INFO
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.manager.example.com:7051
      - CORE_PEER_LOCALMSPID=ManagerMSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/manager.example.com/peers/peer0.manager.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/manager.example.com/peers/peer0.manager.example.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/manager.example.com/peers/peer0.manager.example.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/manager.example.com/users/[email protected]/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
        - /var/run/:/host/var/run/
        - ./../chaincode/:/opt/gopath/src/github.com/chaincode
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    depends_on:
      - orderer.example.com
      - peer0.manager.example.com
      - peer1.manager.example.com

    networks:
      - example

Solution

  • I was making a very simple mistake: I was not copying the generated crypto material from one host to another; I was generating new crypto materials on all of the hosts, thinking that they will be the same.