如何将Docker容器中的Node.js连接到Hyperledger Fabric?

时间:2018-05-25 04:47:26

标签: docker hyperledger-fabric hyperledger hyperledger-composer

Dockerfile

FROM node:carbon
WORKDIR /usr/src/app
COPY package*.json ./
COPY *.card ./
RUN npm install
RUN ./node_modules/.bin/composer card import --file admin@biznetwork.card --card admin@biznetwork
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]

connection.js用于创建admin@biznetwork.card (我用正在运行的容器名称替换了“:// localhost:port”) enter image description here

{  
    "name":"hlfv1",
    "x-type":"hlfv1",
    "x-commitTimeout":300,
    "version":"1.0.0",
    "client":{  
       "organization":"Org1",
       "connection":{  
          "timeout":{  
             "peer":{  
                "endorser":"300",
                "eventHub":"300",
                "eventReg":"300"
             },
             "orderer":"300"
          }
       }
    },
    "channels":{  
       "composerchannel":{  
          "orderers":[  
             "orderer.example.com"
          ],
          "peers":{  
             "peer0.org1.example.com":{  

             }
          }
       }
    },
    "organizations":{  
       "Org1":{  
          "mspid":"Org1MSP",
          "peers":[  
             "peer0.org1.example.com"
          ],
          "certificateAuthorities":[  
             "ca.org1.example.com"
          ]
       }
    },
    "orderers":{  
       "orderer.example.com":{  
          "url":"grpc://orderer.example.com:7050"
       }
    },
    "peers":{  
       "peer0.org1.example.com":{  
          "url":"grpc://peer0.org1.example.com:7051",
          "eventUrl":"grpc://peer0.org1.example.com:7053"
       }
    },
    "certificateAuthorities":{  
       "ca.org1.example.com":{  
          "url":"http://ca.org1.example.com:7054",
          "caName":"ca.org1.example.com"
       }
    }
 }

Node.js应用无法连接并收到错误:

(node:17) UnhandledPromiseRejectionWarning: Error: Error trying to ping. Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: Error: The current identity, with the name 'admin' and the identifier 'fcb2071b5df74a16b4b93b14bff69af15c1104df6465a23ae4ec3473cc663d71', has not been registered

感觉我可能会对卡片做错了,因为

RUN ./node_modules/.bin/composer card import --file admin@biznetwork.card --card admin@biznetwork
RUN ./node_modules/.bin/composer network ping --card admin@biznetwork

无法连接。

1 个答案:

答案 0 :(得分:1)

我认为您需要将Docker主机的~/.composer/cards映射到容器的~/.composer/cards