[英]How to run hyperledger fabric REST api from chrome postman
Hi All I have setup hyperledger project in my laptop win 7 using docker toolbox. 大家好我使用docker toolbox在我的笔记本电脑win 7中设置了hyperledger项目。 I have peer and membersrvc conatiners running.
我有peer和membersrvc着色器正在运行。 and also I am able to invoke and query chaincode like
peer chaincode query -l golang -n mycc -c '{"Args": ["query", "b"]}'
and also able to use curl command for REST api from inside docker-machine 而且我还能够调用和查询链代码,例如
peer chaincode query -l golang -n mycc -c '{"Args": ["query", "b"]}'
并且还可以使用curl命令从REST api在docker-machine内部
docker-machine ssh default
docker-machine ssh默认
curl -H "Content-Type: application/json" -X POST -d '{ "jsonrpc": "2.0", "method": "query", "params": {"type": 1,"chaincodeID":{"name":"mycc"},"ctorMsg": {"args":["query", "a"]},"secureContext": "jim" }, "id":5}' 172.17.0.3:7050/chaincode
But problem is not able to access this same REST api "172.17.0.3:7050/chaincode" from browser. 但是问题无法从浏览器访问相同的REST api“ 172.17.0.3:7050/chaincode”。 my docker machine ip is : 192.168.99.100
我的docker机器ip是:192.168.99.100
peer ip : 172.17.0.3 对等IP:172.17.0.3
Rest API port : 7050 其余API端口:7050
I tried with all the possible IP and port combination for peer but its not accessible from browser. 我尝试使用对等体的所有可能的IP和端口组合,但无法从浏览器访问它。 Can you help me what IP and port combination should I use to access REST api from browser.
您能帮我从浏览器访问REST API的IP和端口组合吗? And how I can find the API.
以及如何找到API。
You need to use the IP address of the "Docker machine" - which in this case is 192.168.99.100 ( http://192.168.99.100:7050 for REST) 您需要使用“ Docker机器”的IP地址-在这种情况下为192.168.99.100 (对于REST是http://192.168.99.100:7050 )
The Swagger doc for the REST API can be found at https://github.com/hyperledger/fabric/blob/v0.6/core/rest/rest_api.json REST API的Swagger文档可在https://github.com/hyperledger/fabric/blob/v0.6/core/rest/rest_api.json找到
Answer to this is: 答案是:
Map default REST port in docker-compose.yml file 在docker-compose.yml文件中映射默认的REST端口
membersrvc:
image: hyperledger/fabric-membersrvc
command: membersrvc
vp0:
image: hyperledger/fabric-peer
ports:
- "7050:7050"
environment:
- CORE_PEER_ADDRESSAUTODETECT=true
- CORE_VM_ENDPOINT=http://localhost:2375
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_ID=vp0
- 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_SECURITY_ENROLLID=test_vp0
- CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
links:
- membersrvc
command: sh -c "sleep 5; peer node start --peer-chaincodedev"
Now this 7050 port is used under the VM so we should map this port to some other port on windows for example 3000 现在在虚拟机下使用了7050端口,因此我们应将此端口映射到Windows上的其他端口,例如3000
What you need to understand is that in this setup, with the Docker Toolkit, you actually have two different levels of port mapping. 您需要了解的是,在此设置中,使用Docker Toolkit,您实际上具有两种不同级别的端口映射。 First there is a mapping between the container and the linux VM docker runs in, then there is a mapping between the linux VM and Windows.
首先,在容器和运行中的linux VM之间存在一个映射,然后在linux VM和Windows之间存在一个映射。 The mapping specified in your docker-compose.yml file only affects the former.
在docker-compose.yml文件中指定的映射仅影响前者。 For the latter you need to set that on VirtualBox.
对于后者,您需要在VirtualBox上进行设置。
To set the second mapping launch the VirtualBox Manager. 要设置第二个映射,请启动VirtualBox Manager。
Select the running VM called “default”. 选择正在运行的虚拟机,称为“默认”。 Click on “Settings”.
点击“设置”。 Select “Network”.
选择“网络”。
Open the “Advanced” section and click on “Port Forwarding”. 打开“高级”部分,然后单击“端口转发”。 Click the “Adds new port forwarding rule” button on the right (the green diamond with a plus sign).
单击右侧的“添加新端口转发规则”按钮(带加号的绿色菱形)。 Then set Host Port to 3000 and Guest Port to 7050.
然后将“主机端口”设置为3000,将“访客端口”设置为7050。
Click Ok. 单击确定。 That's it.
而已。
Now, point your browser to https://localhost:3000/network/peers You should get a page returned from your running peer listing one peer: 现在,将浏览器指向https:// localhost:3000 / network / peers您应该从正在运行的对等方返回的页面列出一个对等方:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.