Konstantin Narkhov
Pheix 0.8.96
@condemnedcell
konstantinnarkhov.pro

Decentralized ethereum application development with docker

29 october, 2018


Intro

A few months ago I have started experiments with ethereum private networks. The first task was to setup network on virtual machine. I have started with Fedora 20 (there was a free vm on my server), but after a few days have given up. Installation trace: start, end. I should mention that I have setup Go language and Go-Ethereum suite on FC20 successfully, but failed with Solidity.

At the next step I have installed Debian 9.4 virtual machine and deployed Go language, Go-Ethereum and Solidity there. But when I have tried to repeat install on my Debian 9.4 VPS I’ve got this issue, after a quick research I have fixed the error and the issue has been closed (see link below for details).

You could ask me — why I’m telling you these stories?! The answer is simple — now I’m using docker and have no any troubles.

A few days ago I have created a configuration file for Docker. With this config you can build full functional image for Ethereum development — pre-installed Go language, Go-Ethereum, Solidity and Ethereum private network example.


Quick start

If you have no enough time to wait while docker image will build (it takes ~ 30 min on vm), you can pull pre-built docker image from my registry (registry.gitlab.com/pheix-pool/docker-ethereum) and start development of your decentralized apps right now. Follow these steps:

1. Pull the image:

sudo docker pull registry.gitlab.com/pheix-pool/docker-ethereum

2. Create an alias for pulled image:

sudo docker tag registry.gitlab.com/pheix-pool/docker-ethereum ethereum-dev

3. Run this image with bridged network from container to host:

sudo docker run --net=host -it ethereum-dev

4. Start local private ethereum network within container:

root@localhost:/ethereum-local-network/devnet.local# ./start-all-in-screen.sh

Attach to the Docker container and Ethereum nodes

After these steps you will got working local ethereum private network with 2 nodes. First node is available at http://127.0.0.1:8501, second node is available at: http://127.0.0.1:8502. To connect to these nodes via RPC-JSON from host just threw http-request from your app.

To connect to these nodes via geth attach to the working ethereum-dev container

sudo docker attach

Inside container attach to screen with command:

root@localhost:/ethereum-local-network/devnet.local# screen -x

Then create a new window with Ctrl+A C and run:

root@localhost:/ethereum-local-network/devnet.local# geth attach http://127.0.0.1:8501

You will attach to the first node. Create a new window with Ctrl+A C again and run:

root@localhost:/ethereum-local-network/devnet.local# geth attach http://127.0.0.1:8502

You will attach to the second node. To detach screen press Ctrl+A D, to detach container just run exit in command line.


Local private network example

Local ethereum private network example is based on this manual, and contains twin-node setup with bash script automation. Repository with example is available on gitlab.com. In dev.local folder there are:

  1. Node folders with private data (keys, passwords);

  2. Genesis block;

  3. Bootnode enode;

  4. Accounts data (hashes and passwords);

  5. reinit.sh — bash script for node reinitializion, it clear previous blockchain and initializes nodes with genesis block;

  6. start.bootnode.sh, start.node1.sh, start.node2.sh — bash scripts for node startup;

  7. start-all-in-screen.sh — bash script for node startup in screen, it start all network nodes (bootnode, node1 and node2) in different windows of screen app; you can attach to this screen via screen -x command and browse windows with Ctrl+A N or Ctrl+A P commands.

Blog entries

Check out latest blog entries: most interesting stories about past events & activities.

Quick feedback

Letters and spaces only