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

How to connect Node.js in Docker container to Hyperledger Fabric?

Docker 文件

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”)

{  
    "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

未连接。

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