Running Pchain in Docker

One of the quickest ways to get Pchain up and running on your machine is by using Docker.

Install Docker

Get docker on Ubuntu

If your PC's operating system is Ubuntu, you can get docker as follows:

sudo apt-get remove docker docker-engine docker-ce
sudo apt-get install  docker
sudo apt-get install -y
sudo apt-get install  docker-registry
sudo systemctl start docker
sudo systemctl enable docker

To see more details, you can see the Docker Official install Guide (Ubuntu).

Note: To install Docker CE, you need the 64-bit version of one of these Ubuntu versions:

  • Bionic 18.04 (LTS)

  • Xenial 16.04 (LTS)

  • Trusty 14.04 (LTS)

Get docker on Windows and Mac OS

You can find the install package on the Docker Official website. If you want to run docker on windows, DO NOT use windows containers but use Linux containers. And make sure the Virtualization Technology is enabled. To see more details, you can see the Docker Official install Guide (Windows) and Docker Official install Guide (Mac OS).

Running docker requires a 64-bit operating system, win7 or higher, and supports " Hardware Virtualization Technology", and "virtualization" is available.

Build Pchain Dockerfile

To Run Pchain on dockers, you will make a Pchain docker image from Dockerfile as follows from within a pchain folder:

cd pchain
docker build -t pchian . 

You can check the image status by:

& docker images

If the Pchain image has been built correctly, you can find an image called pchain and the Tag is latest.

Start the containers

When the Pchain's docker image has been built, you can start Pchian in docker:

& docker run -it pchain

And you can see the containers status:

$ docker ps -a

Single-node on docker

To run a single-node Pchain in docker, execute docker run -it pchain. And create accounts with a specified balance, will generate eth_genesis.json:

./pchain --datadir pchainData init_eth_genesis "{10000000000000000000000000000000000, 100}"

Generate the Pchain genesis.json with epoch/reward scheme parameters:

./pchain --datadir pchainData init pchainData/pchain/eth_genesis.json

to start the node:


Multi-node on docker

You can deploy multiple nodes through docker in order to test jobs, smart contracts and child chains.

Add an ordinary node

Start another docker container, build a fresh node('B') but don't start it (not run the ./ Here are the steps to make the new node ('B') join the existing node ('A'):

  • stop Pchain on A

  • add the peer entry,

    • add B's ip:port(say to A's config.toml,

    • add A's ip:port(say to B's config.toml. Then, A's config.toml should look like:

#This is a TOML config file.
moniker = "anonymous"
node_laddr = "tcp://"
seeds = ""
fast_sync = true
db_backend = "leveldb"
log_level = "notice"

Note: For more information, see toml official guide.

  • Copy A's genesis.json and eth_genesis.json to B, make their genesis.json keep the same, therefore the validators are the same between A and B.

  • Add A's enode to B, you can get A's enode by RPC command as follows:

curl -H "Content-Type:application/json" -X POST -d '{"method": "admin_nodeInfo", "params": [],"id":1}' "http://x.x.x.x/pchain"
  • Run Pchain on A and B (order is not relevant). After they are connected, B should start to synchronize blocks from A, and they will have the same blockchain behaviors when synchronization is complete.

Add a validator node

In order to add a validator node, there must be existing validators.

  • Start a new container from Pchain image, add a new node ('C') to the existing network but don't start it (not run the ./

  • Pick one validator (node 'A'), add C's pub-key (the long hex-string of pub_key part in /path/to/priv_validator.json) to A's validators part in A's /path/to/genesis.json. then A's validators" part in genesis.json should look like:

"validators": [
                		"eth_account": "0x7eff122b94897ea5b0e2a9abf47b86337fafebdc"
                        "amount": 10,
                        "name": "",
                        "pub_key": [
                { #here is C's pub-key part
                        "eth_account": "0x32ef122b94897ea5b0e2a9abf4cda6337fafebdc"
                        "amount": 10,	#vote power
                        "name": "",   #name, could be empty
                        "pub_key": [  #pub-key part
                                "E94937710077B38C2A1334B89B394D61CFBFEE732A54F9358A73E36ED0827B9A" #copy from C's priv_validator.json

Important: Make sure C's amount is smaller than 1/2 of the sum of all other validators' amount in order to maintain fault-tolerant consensus

  • Copy A's genesis.json and eth_genesis.json to all other nodes within the network, including C.

  • Stop all nodes within the network.

  • Start all nodes with C the last one to start.

  • Extension: This should work for batch-addition of new validators.

Multi-node automated deployment

openssh-server net-tools curl are installed in images. And all operation commands are contained in You might execute this command step by step but not in one time.