Running a Private Blockchain Node
In this article, I will try to explain how you can create private Ethereum blockchain testing node on your system using a Docker image. Before starting, I will try to give a small overview of the Docker.
What is Docker?
Do you remember the age when we had to buy a sophisticated server for every single online application that we had to build? That era was costly because if you would invest your money to create an online application, then you have to think about the server as well, e.g. (Shared Hosting / Dedicated Server). Then VMWare era came, and we reached to the point where one hardware server can support multiple online applications with their separate OS / RAM and storage. So all the OS images were sharing a single machine and it had drastically changed the hardware cost, and everything turned into a virtual.
But now this virtualization is considered expensive for the applications because the more we are moving into the future, the more numbers of applications are produced. So supporting multiple OS on a single server is doable but expensive concerning the memory, storage and cumbersome OS processes consumptions that sometimes make you forced to buy another hardware with another VMWARE and OS licenses.
Containers are the new technology which has decreased the cost and anomalies of the OS based Virtualization. The container came with the concept of having a stripped-down very lightweight version of the OS along with the product or application.
This new technology has made few significant effects in the development world
- Now developer does not need to worry about the environment where his application will run, e.g., OS, File system, drives, etc. The container itself has a lightweight version of the OS with its filesystem along with the application.
- The developer can run many instances of his application within one OS regardless if it is virtual or physical. Each container acts like a process independently which has its file system and OS.
- You can create a Docker image where you can define the OS, application and its prerequisites within the file system. The container process is the runtime version of the image.
Virtual-box is the technology which is used by the Docker to create multiple containers. Due to this technique, I can run two different nodes within one host or machine or VM. I can release them to the production server without any hard configuration or environmental changes required in the host OS. So the production and testing server needs only Docker engine and rest of the thing will be taken care of by the product’s image and its runtime version “Container.”
Docker Inc. is a company who has built and provided Docker Engine and development Kit, which you can use for creating and composing Docker containers and images. For more detail check Docker’s documentation.
Ethereum and Docker:
As you know, we are talking about decentralized technology where we have to run peer to peer nodes. The best way is by using Docker containers which will contain the Ethereum network environment and client. Also, you can scale these nodes on your computer without worrying about an extra server or Vmware images.
So lets build your first Blockchain private network on the Ethereum node:
- You should have 64bit OS either Ubuntu /linux or windows.
- Pull the source code or visit the Github link and download all these files in the folder: https://github.com/Capgemini-AIE/Ethereum-Docker
- If you do not have Docker then visit this link and download the Suitable Docker version e.g. community or enterprise. For testing purpose we will use community version https://www.Docker.com/get-Docker
- If you are on Windows 10 professional or ultimate then download Dockers for Windows / if you are on Windows 10 home then download Docker toolbox. For windows Home try this link for detail https://forums.Docker.com/t/installing-Docker-on-windows-10-home/11722/2
- Sometime Virtual-box makes problem, if you face any problem on Windows then make sure to uninstall the existing Virtual-box and let Docker install the compatible version for you.
- For virtual box driver conflicts check this link https://dottech.org/101997/how-to-uninstall-virtualbox-drivers-on-windows/
Now we are ready to build our first blockchain private node.
Start the Shell
Go to the installed Docker directory and run the official Docker’s console. If you have installed Dockers toolbox, then click Quick Start Terminal. It will take you to the Docker’s console where we will create new containers for the Ethereum process. Go to the source directory which you have downloaded.
Docker with Ethereum
Here you will see some files and folders.
Docker Compose and Image Pull
Now we will build the single test Ethereum node
Let’s use this command
Docker-compose -f Docker-compose-standalone.yml up -d
This command will pull the image from the Docker hub (Docker hub is like a central repository of Docker’s images). It will take few minutes to download relevant images within your system. If you are using Linux server of your Docker, then all the images will be stored under the Linux image. Otherwise, for windows server, all images will be saved under Hyper-V directory. C:\Users\Public\Documents\Hyper-V\
Since I am building on Windows home, so I do not have Hyper-V enabled directory, and my all images are saved under the Linux server of the Docker. You can also check what server and client versions you have for your existing Docker setups.
Write “docker version” command on the quick start shell of the Docker.
Here you can see the server is linux which is by default version when you install Docker on your windows.
By default our previous docker command will create three containers
- 1 Ethereum Bootstrap container
- 1 Ethereum container and connect it with the bootstrap container
- 1 NetState container
The NetState container’s application will allow you to see the status of your private Ethereum node.
To access the netstate container to see the activities of your ethereum node you can view it through
http://$(docker-machine IP default):3000
Congratulation you have built your private blockchain. This step is just a baby step towards Ethereum. In my next article, I will explain more in detail how to use better tools and other approaches to run Ethereum node. This article will give you some overview of the Docker and how Docker can utilize Ethereum nodes images to create containers. This understanding is essential since in future we will be working with several peers to peer nodes and to simulate this type of mesh network Docker is a savior for us.