It’s really, really hot and humid down here in sunny Florida. So, I got my tennis in early this weekend¬†(it was still really hot!) and then settled in for a little experimentation for the rest of the long, hot days. I’ve been wanting¬†to install Docker for Mac (Beta) ever since it was released, but¬†haven’t had the time.
First thing is that Docker for Mac does not run in, or require, Vagrant; it runs natively using HyperKit. It also doesn’t support routing IP traffic to and from containers. You can, however, expose ports and container linking works just fine.
I was also interested in making Hyperledger Fabric a bit more accessible. The current docs seem to be very much oriented to someone developing the Fabric. Now that we have a release and have published images for the fabric-peer and fabric-membersrvcs to DockerHub, we need to start orienting towards those who simply want to run the Hyperledger Fabric and develop chaincode and blockchain applications.
The current documentation requires that you install the development environment, which is rather involved and somewhat unnecessary for those of you simply seeking to try out the platform and develop an application.
Here’s what you’ll need:
- a Mac
- Docker for Mac (Beta)¬†
The Hyperledger Fabric project currently only supports writing chaincode in Go, so if you intend to do any chaincode development, you’ll need to install Go – though within the next couple of weeks we hope to have the Java chaincode shim merged, which will open up the ability to use Java.
Create a directory in your development workspace. Next, you’ll need to create a compose file. Take a look at the compose files we have in the Hyperledger Fabric’s¬†integration tests if you’d like to experiment with additional levels of complexity (e.g. more peer nodes, member services, etc). We’ll start with a very simple single node deployment.
Create a docker-compose.yml file and add the following content:
vp: image: hyperledger/fabric-peer ports: - "5000:5000" environment: - CORE_PEER_ADDRESSAUTODETECT=true - CORE_VM_ENDPOINT=http://127.0.0.1:2375 - CORE_LOGGING_LEVEL=DEBUG command: peer node start
If you compare this compose file with the others I referenced above, you’ll note two differences:
- the CORE_VM_ENDPOINT is set to localhost rather than the Vagrant IP
- the ports section which exposes the peer’s container port 5000 on the host
It should be noted that running multiple peers will require that you expose only one peer’s container ports on the host or you’ll have port collisions. However, for developing¬†applications or chaincode on your Mac, a single peer node running the ‘noops’ consensus should be more than adequate for your needs.
You should now be able to start up a peer node using the
docker-compose up command. Give it a try. Running
docker ps should return something like the following:
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c1ada03e6c40 hyperledger/fabric-peer "peer node start" 15 hours ago Up 26 seconds 0.0.0.0:5000->5000/tcp hlp_vp_1
You should now be able to interact with your peer. It isn’t running PBFT consensus, but for purposes of development, that shouldn’t be necessary. It is also running without the membersrvc service which means security is disabled. If you want to have both services running, add the following to your docker-compose.yml, and rerun
membersrvc: image: hyperledger/fabric-membersrvc command: membersrvc
There are a few ways to start interacting with your peer, but now that you have a peer up and running, you should be able to bypass creating a Hyperledger Fabric development environment and get right to the process of writing chaincode or leveraging the Node SDK to write an application.