** Important Note: Parts of this article are now obsolete, please check the update: Running Hyperledger Fabric on Windows – Revised. **
My colleague Chris Ferris recently posted on how he got to run the Hyperledger Fabric natively on Mac. Knowing that I have a Windows machine he prompted me to try and do the same on Windows. So I did and here is what I can say about my experiment.
First, I need to say that in my case I have to put ‚Äúnatively‚ÄĚ between quotes because the Windows machine I have is running Windows 7 and Docker doesn’t actually run natively on that version of Windows. Docker currently only runs natively on Windows 10. For older versions of Windows you have to use the Docker Toolbox which actually runs Docker in a linux VM.
If you haven’t installed VirtualBox yet you first need to do that. The installation is very straightforward, the only possible gotcha is that you need to make sure virtualization is on on your machine. This is set via the BIOS menu so if it doesn’t work you will need to reboot your machine to change that setting.
Having already installed VirtualBox on my machine I had that already taken care of.
As explained above I couldn’t run Docker natively on my machine so I installed Docker Toolbox. This was very straightforward. Once the installation ends you simply launch the “Docker Quickstart Terminal” and you’re on your way.
The command actually provisions a linux VM in VirtualBox with Docker. You can see the running VM by opening the VirtualBox Manager.
Note that on starting the Docker Quickstart Terminal I get an error message saying that
bash: .bashrc: No such file or directory but that’s not a problem.
You then need to create a file docker-compose.yml similar to the one Chris created for running on Mac.
To make it easy you can simply copy paste the following or copy compose-defaults.yml from the fabric distribution and then make the same two changes Chris discussed to 1) change the endpoint and 2) add a port mapping.
Your docker-compose.yml file should then contain the following:
vp: image: hyperledger/fabric-peer ports: - "5000:5000" environment: - CORE_PEER_ADDRESSAUTODETECT=true - CORE_VM_ENDPOINT=http://localhost:2375 # TODO: This is currently required due to BUG in variant logic based upon log level. - CORE_LOGGING_LEVEL=DEBUG # Startup of peer must be delayed to allow membersrvc to come up first command: sh -c "sleep 5; peer node start" #command: peer node start # Use these options if coverage desired for peers #image: hyperledger/fabric-peer-coverage #command: ./peer.test --test.coverprofile=coverage.cov node start membersrvc: image: hyperledger/fabric-membersrvc command: membersrvc
With this being done you can then fire up an Hyperledger Fabric peer with the following command:
This will fetch the Hyperledger Fabric container from the cloud using Docker Hub and launch it within the VM that is running.
This may take a bit of time at first as it downloads the workload from the net but eventually you should start seeing log messages scrolling through your terminal window indicating that the Fabric peer is running and waiting for requests like this:
... [36mvp_1 |[0m 21:06:38.558 [rest] StartOpenchainRESTServer -> INFO 030[0m Initializing the REST service on 0.0.0.0:5000, TLS is disabled. [36mvp_1 |[0m 21:06:44.558 [peer] ensureConnected -> INFO 031[0m Touch service indicates no dropped connections [36mvp_1 |[0m [36m21:06:44.558 [peer] ensureConnected -> DEBU 032[0m Connected to:  [36mvp_1 |[0m [36m21:06:44.558 [peer] ensureConnected -> DEBU 033[0m Discovery knows about:  [36mvp_1 |[0m 21:06:50.558 [peer] ensureConnected -> INFO 034[0m Touch service indicates no dropped connections
Up to that point my experience had been so smooth it made me wonder if it was really running! So, I decided to go one step further and try to connect to it and check that it was indeed running.
Connecting to your peer
There are different ways one can interact with an Hyperledger Fabric peer but of course the easiest way to do a simpe test is to use the REST API. That’s the power of the web, all you need is a web browser.
One very simple request you can make to your peer is for the list of peers running in the network. This can normally be done by pointing your browser to: https://localhost:5000/network/peers
Unfortunately this is where things became difficult for me. First, I already knew that port 5000 isn’t available on Windows. It is used by the OS so you have to map it to a different port, say 3000.
At this point I thought all I had to do was to change my docker-compose.yml file to map port 3000 to 5000 but that didn’t work. It took me a while to understand but after many tries I figured it out so I’ll just give you the solution and spare you with my fruitless wandering.
What you need to understand is that in this setup, with the Docker Toolkit, you actually have two different levels of port mapping. 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. The mapping specified in your docker-compose.yml file only affects the former. For the latter you need to set that on VirtualBox.
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 5000.
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:
Congratulations! You have successfully connected to your peer.