首页 > 解决方案 > 容器化区块链微服务

问题描述

如果我在主机上托管我的微服务,它会按预期工作,但如果我在容器中托管相同的东西,我会收到以下错误:


2020-09-27T08:35:06.099Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Committer- name: orderer2.audit.blockit.co:9050, url:grpcs://localhost:9050, connected:false, connectAttempted:true
2020-09-27T08:35:06.099Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server orderer2.audit.blockit.co:9050 url:grpcs://localhost:9050 timeout:3000
2020-09-27T08:35:06.100Z - error: [DiscoveryService]: _buildOrderer[blockit] - Unable to connect to the discovered orderer orderer2.audit.blockit.co:9050 due to Error: Failed to connect before the deadline on Committer- name: orderer2.audit.blockit.co:9050, url:grpcs://localhost:9050, connected:false, connectAttempted:true
2020-09-27T08:35:09.108Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer2.blockit.co:9051, url:grpcs://localhost:9051, connected:false, connectAttempted:true
2020-09-27T08:35:09.109Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer2.blockit.co:9051 url:grpcs://localhost:9051 timeout:3000
2020-09-27T08:35:09.109Z - error: [DiscoveryService]: _buildPeer[blockit] - Unable to connect to the discovered peer peer2.blockit.co:9051 due to Error: Failed to connect before the deadline on Endorser- name: peer2.blockit.co:9051, url:grpcs://localhost:9051, connected:false, connectAttempted:true
2020-09-27T08:35:12.113Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.blockit.co:7051, url:grpcs://localhost:7051, connected:false, connectAttempted:true
2020-09-27T08:35:12.114Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.blockit.co:7051 url:grpcs://localhost:7051 timeout:3000
2020-09-27T08:35:12.114Z - error: [DiscoveryService]: _buildPeer[blockit] - Unable to connect to the discovered peer peer0.blockit.co:7051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.blockit.co:7051, url:grpcs://localhost:7051, connected:false, connectAttempted:true
2020-09-27T08:35:15.118Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer1.blockit.co:8051, url:grpcs://localhost:8051, connected:false, connectAttempted:true
2020-09-27T08:35:15.119Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer1.blockit.co:8051 url:grpcs://localhost:8051 timeout:3000
2020-09-27T08:35:15.119Z - error: [DiscoveryService]: _buildPeer[blockit] - Unable to connect to the discovered peer peer1.blockit.co:8051 due to Error: Failed to connect before the deadline on Endorser- name: peer1.blockit.co:8051, url:grpcs://localhost:8051, connected:false, connectAttempted:true
2020-09-27T08:35:15.145Z - error: [RoundRobinQueryHandler]: evaluate: message=Query failed. Errors: [], stack=FabricError: Query failed. Errors: []
at RoundRobinQueryHandler.evaluate (/app/microservice/node_modules/fabric-network/lib/impl/query/roundrobinqueryhandler.js:46:23)
at Transaction.evaluate (/app/microservice/node_modules/fabric-network/lib/transaction.js:278:49)
at FabricRepository.<anonymous> (/app/microservice/dist/services/blockchain-client.js:206:51)
at Generator.next (<anonymous>)
at fulfilled (/app/microservice/dist/services/blockchain-client.js:5:58)
at processTicksAndRejections (internal/process/task_queues.js:97:5), name=FabricError
queryChaincode Error: Cannot query from blockchain: Query failed. Errors: []
at FabricRepository.<anonymous> (/app/microservice/dist/services/blockchain-client.js:213:23)
at Generator.throw (<anonymous>)
at rejected (/app/microservice/dist/services/blockchain-client.js:6:65)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
POST /fabric-service/queryChaincode 18184.858

任何想法为什么?

标签: node.jshyperledger-fabricdocker-swarm

解决方案


在此处的输出中,您可以看到

2020-09-27T08:35:15.119Z - error: [DiscoveryService]: _buildPeer[blockit] - Unable to connect to the discovered peer peer1.blockit.co:8051 due to Error: Failed to connect before the deadline on Endorser- name: peer1.blockit.co:8051, url:grpcs://localhost:8051, connected:false, connectAttempted:true

它正在尝试连接到 localhost:8051。当 localhost 解析为您在其中运行应用程序的容器时,它不会找到它。您可能正在解析为 localhost 因为您已asLocalHost为您的应用程序设置为 true 您需要将此选项设置为 false 并确保您所在容器中的应用程序可以解析为您定义的预期主机名


推荐阅读