In July 2016 I wrote a blog post on Running Hyperledger Fabric “natively” on Windows that has, judging by the comments I received, helped quite a few people.

I’m glad this turned out to be so useful but, that article has now become in part obsolete because it refers in the last section to a REST API which is no longer available in Fabric. This is understandably confusing people so, this new article provides some much needed update.

What has changed: Fabric’s REST API

Fabric has gone through a major redesign that led to the (temporary) removal of the REST API starting with Fabric 1.0 released earlier this year. A new REST API is under development and will be part of a future version but in the meantime the REST API that was supported in Fabric 0.6 and earlier versions is no longer supported. The main API for Fabric 1.0 is the native gRPC API.

This means that the last section of the July 2016 article that refers to the REST API is no longer relevant. Some things haven’t changed though.

What has not changed: Installing Docker or Docker Toolbox

If you are using Windows 10 by all means use Docker for Windows 10 which provides native support for Docker on Windows. In this case, you shouldn’t need to do anything special and Fabric should run without problems out of the box. Just make sure to read the prerequisites section and follow the documentation on Getting Started with Fabric, .

If on the other hand you are using an earlier version of Windows, such as Windows 7, you are stuck using Docker Toolbox and you will inevitably have to deal with the additional layer this involves. Read on to find out what this entails.

Docker Toolbox and Port forwarding

As explained in the previous article, Docker Toolbox provides support for Docker by running Docker inside a Linux Virtual Machine on top of Windows using VirtualBox. This has consequences when it comes to trying to communicate with your containers because there is an extra layer you need to open up for communication, namely the VirtualBox (the VM within it, that is).

While Fabric 1.0 doesn’t support the REST API that was discussed in the last section of the July 2016 article, the problem of port forwarding that was discussed still very much exists when using the gRPC API and needs to be dealt with in a similar way. The ports involved are however different. Let’s get through the Writing Your First Application tutorial.

Writing Your First Fabric Application on Windows 7

You should be able to get through all the steps up to Register and Enroll user1 without problems. However trying to execute the next node command node registerUser.js will fail with an error like this:

$ node registerUser
Store path:C:\Users\lehors\Projects\Go\src\github.com\hyperledger\fabric-sample
s\fabcar\hfc-key-store
Successfully loaded admin from persistence
Failed to register: Error: Calling register endpoint failed with error [Error: c
onnect ECONNREFUSED 127.0.0.1:7054]

The reason is that this command requires connecting to the fabric certificate authority (fabric-ca) through port 7054 which is not open. This is the first port to forward.

As explained in the first article, port forwarding can be set by going to the VirtualBox client and adding this setting to the VM. In the VirtualBox client, select the “default” VM, click “Settings”, “Network”, “Advanced”, and “Port Forwarding”. Create a new rule by clicking the “+” sign on the right and entering the following: Name -> “ca”, Host Port -> 7054, Guest Port -> 7054. Click “OK”, Click “OK” again. You can leave the Host IP and Guest IP unspecified.

Now, back to your Docker Toolbox Terminal window, try the node command again. This time it should succeed:

$ node registerUser.js
 Store path:C:\Users\lehors\Projects\Go\src\github.com\hyperledger\fabric-sample
s\fabcar\hfc-key-store
Successfully loaded admin from persistence
Successfully registered user1 - secret:DnQUbKqPWqWd
Successfully enrolled member user "user1"
User1 was successfully registered and enrolled and is ready to intreact with the
 fabric network

Next, in the Querying the Ledger section, the tutorial will instruct you to execute the command node query.js. this command will fail with an error like this:

$ node query.js
Store path:C:\Users\lehors\Projects\Go\src\github.com\hyperledger\fabric-samples
\fabcar\hfc-key-store
Successfully loaded user1 from persistence
error: [client-utils.js]: sendPeersProposal - Promise is rejected: Error: Connec
t Failed
    at C:\Users\lehors\Projects\Go\src\github.com\hyperledger\fabric-samples\fab
car\node_modules\grpc\src\client.js:554:15
Query has completed, checking results
error from query =  { Error: Connect Failed
    at C:\Users\lehors\Projects\Go\src\github.com\hyperledger\fabric-samples\fab
car\node_modules\grpc\src\client.js:554:15 code: 14, metadata: Metadata { _inter
nal_repr: {} } }

As in the previous step, the command fails due to a connection error. However, this time it fails because it tried to connect to the peer. There are two ports associated with the peer we need to worry about: 7051 to which requests are sent and 7053 from which events are emitted. For a query, only the first one is necessary. You can just add a port forwarding: Name -> “peer”, Host Port -> 7051, Guest Port -> 7051. And while there you might as well also add the rule for the events: Name -> “peer_event”, Host Port -> 7053, Guest Port -> 7053.

The command should now succeed:

$ node query.js
Store path:C:\Users\lehors\Projects\Go\src\github.com\hyperledger\fabric-samples
\fabcar\hfc-key-store
Successfully loaded user1 from persistence
Query has completed, checking results
Response is  [{"Key":"CAR0", "Record":{"colour":"blue","make":"Toyota","model":"
Prius","owner":"Tomoko"}},{"Key":"CAR1", "Record":{"colour":"red","make":"Ford",
"model":"Mustang","owner":"Brad"}},{"Key":"CAR2", "Record":{"colour":"green","ma
ke":"Hyundai","model":"Tucson","owner":"Jin Soo"}},{"Key":"CAR3", "Record":{"col
our":"yellow","make":"Volkswagen","model":"Passat","owner":"Max"}},{"Key":"CAR4"
, "Record":{"colour":"black","make":"Tesla","model":"S","owner":"Adriana"}},{"Ke
y":"CAR5", "Record":{"colour":"purple","make":"Peugeot","model":"205","owner":"M
ichel"}},{"Key":"CAR6", "Record":{"colour":"white","make":"Chery","model":"S22L"
,"owner":"Aarav"}},{"Key":"CAR7", "Record":{"colour":"violet","make":"Fiat","mod
el":"Punto","owner":"Pari"}},{"Key":"CAR8", "Record":{"colour":"indigo","make":"
Tata","model":"Nano","owner":"Valeria"}},{"Key":"CAR9", "Record":{"colour":"brow
n","make":"Holden","model":"Barina","owner":"Shotaro"}}]

You can go through the rest of the section involving query.js with that setup. However, when getting to the next section on Updating the Ledger the command node invoke.js will fail with an error like this:

$ node invoke.js
Store path:C:\Users\lehors\Projects\Go\src\github.com\hyperledger\fabric-samples
\fabcar\hfc-key-store
Successfully loaded user1 from persistence
Assigning transaction_id:  c40650f925ec8ddebcff2938692c22e9b5b03d4b5a951cd1582e7
1360c5ababa
Transaction proposal was good
Successfully sent Proposal and received ProposalResponse: Status - 200, message
- "OK"
info: [EventHub.js]: _connect - options {}
error: [Orderer.js]: sendBroadcast - on error: "Error: Connect Failed\n    at Cl
ientDuplexStream._emitStatusIfDone (C:\\Users\\lehors\\Projects\\Go\\src\\github
.com\\hyperledger\\fabric-samples\\fabcar\\node_modules\\grpc\\src\\client.js:25
5:19)\n    at ClientDuplexStream._readsDone (C:\\Users\\lehors\\Projects\\Go\\sr
c\\github.com\\hyperledger\\fabric-samples\\fabcar\\node_modules\\grpc\\src\\cli
ent.js:221:8)\n    at readCallback (C:\\Users\\lehors\\Projects\\Go\\src\\github
.com\\hyperledger\\fabric-samples\\fabcar\\node_modules\\grpc\\src\\client.js:28
3:12)"
Failed to invoke successfully :: Error: SERVICE_UNAVAILABLE

The command successfully sent the request to the peer but it then failed to connect to the orderer (which is responsible for creating the next block on the chain).
Again, we need to forward the corresponding port. This is port 7050.

So, go back to the VirtualBox and add a rule: Name -> “orderer”, Host Port -> 7050, Guest Port -> 7050.

The node command should now succeed:

$ node invoke.js
Store path:C:\Users\lehors\Projects\Go\src\github.com\hyperledger\fabric-samples
\fabcar\hfc-key-store
Successfully loaded user1 from persistence
Assigning transaction_id:  769c924f6cdffa3d1aca42ff490f2fa00e16e352c2f19fd268459
d409319d950
Transaction proposal was good
Successfully sent Proposal and received ProposalResponse: Status - 200, message
- "OK"
info: [EventHub.js]: _connect - options {}
The transaction has been committed on peer localhost:7053
Send transaction promise and event listener promise have completed
Successfully sent transaction to the orderer.
Successfully committed the change to the ledger by the peer

However, if you neglected to forward the event listener port in the previous step you will get something like this:

$ node invoke.js
Store path:C:\Users\lehors\Projects\Go\src\github.com\hyperledger\fabric-samples
\fabcar\hfc-key-store
Successfully loaded user1 from persistence
Assigning transaction_id:  ebd4381142c63cd6bae7b30a3a12ea84d888fda21846c11578578
5a14dc99867
Transaction proposal was good
Successfully sent Proposal and received ProposalResponse: Status - 200, message
- "OK"
info: [EventHub.js]: _connect - options {}
Failed to invoke successfully :: Error: There was a problem with the eventhub ::
Error: Connect Failed

In that case, just add the port forwarding rule: Name -> “peer_event”, Host Port -> 7053, Guest Port -> 7053.

That’s it.

Summary

Fabric 1.0 doesn’t have a REST API but communicating to the Fabric containers when using Docker Toolbox still requires some care, and a Fabric 1.0 network involves more containers than a Fabric 0.6 network. So to make things work you need to change the related VirtualBox VM settings to add several port forwarding rules. To successfully go through the Writing Your First Application tutorial the following ports need to be forwarded:

ca: 7054, orderer: 7050, peer: 7051, and peer_event: 7053.

This means that the Port forwarding rules dialog box should look like this (the ssh rule is automatically added by Docker Toolbox):

VirtualBox Port Forwarding Rules dialog box showing the different rules set

Note that while this is enough to get you through the Writing Your First Application tutorial, as you build more complex networks, you will need to adjust your settings accordingly.

2 comments on"Running Hyperledger Fabric on Windows – Revised"

  1. Have windows 10 education – is that ok with the Docker windows 10 pro requires?

    • Sorry I don’t know the limits of Windows 10 education. I suggest you give it a try and see how it goes if you haven’t yet.
      And, please, consider posting your findings here so that others can benefit from your experience.
      Thanks.

Join The Discussion

Your email address will not be published. Required fields are marked *