In my previous article about building a blockchain application, I shared some of the tools, tips and techniques I used to create an end-to-end blockchain web application.
Let’s hone in on a specific part of that and explain in more depth how I built an underlying Ethereum private blockchain for testing purposes.
I mentioned that I predominantly used testrpc to stand up a simple, single-node Ethereum instance which had the APIs exposed and some accounts pre-filled with Ether for testing.
Testrpc is a great tool, super simple and fast to get started, which makes it ideal for development and if you are new to the tech. However there are some situations where you might want some extra flexibility or you need to test different scenarios where you require a more “production like” setup. These include -
- Testing the effects of a network of nodes (e.g. a multi-node Ethereum cluster with each node in sync with other nodes via the P2P protocol)
- Access to other Ethereum APIs, for example the management API
- The confidence of developing against a full Geth node
- Easier integration with or ability to test alongside other tools or technology such as IPFS
If you find yourself having to set up a private Ethereum cluster (as I did) you’ll find that it’s not actually a straightforward process.
While there are one or two pretty clear tutorials out there as well as some scripts both for me had some problems. The scripts prefer that you are running Ubuntu, the preferred/recommended platform for Ethereum and the tutorials contain anywhere between 5-20 steps.
Today I’m announcing our open-sourced ethereum-docker which contains a bunch of Dockerfiles and Docker Compose scripts for bringing up standalone full Geth Ethereum nodes or multi-node clusters along with the very nice eth-netstats web dashboard for viewing the status of your cluster.
Let’s take it for a spin.
Starting up a single Ethereum node
Grab the repo -
git clone https://github.com/Capgemini-AIE/ethereum-docker.git cd ethereum-docker
To run a single node do:
docker-compose -f docker-compose-standalone.yml up -d
If you are using Docker-machine with the “default” box you can do:
open http://$(docker-machine ip default):8545
Otherwise on Docker for Mac you can just
open http://localhost:8545 this will give you a connection to the JSON RPC API.
docker exec -it bootstrap geth --datadir=~/.ethereum/devchain attach
To perform tasks like starting and stopping mining you can run:
docker exec -it bootstrap geth --datadir=~/.ethereum/devchain --exec 'miner.stop()' attach
Starting up an Ethereum cluster
To bootstrap the cluster run:
docker-compose up -d
This will create 3 nodes: 2 Ethereum nodes + 1 netstats node. To access netstats UI you can do:
open http://$(docker-machine ip default):3000
Or on Docker for Mac:
And you should see something that looks like:
You can scale the number of Ethereum nodes by doing:
docker-compose scale eth=3
There you go, you have a private Ethereum cluster you can scale up, down and test your applications with.
This provides basic support at the moment for Docker and Docker compose, as always there are a bunch of open tickets on Github for improvements. We would like to add things like support for deploying on top of Kubernetes and Marathon, support for deploying a cluster with IPFS enabled and ability to interact with the cluster nodes and APIs in an easier way.
If you want to give it a try or help out head on over to the Github repository.