Ethereum go-ethereum client docker installation (2) development (dev) environment construction

In the last blog, I described how to build a go-ethereum node based on docker. As a developer, if you simply have a Full node, it is not enough for normal development. For example, when making a transfer transaction, you have to consider whether you have a certain amount of ETC and can you afford the high gas? Based on this, today's blog will introduce how to build a private dev environment.

Method 1: Use existing open source

Let me introduce you to a ready-made ethereum/client-go:test tool image.

download tool

Address: https://github.com/pragmaticcoders/docker-geth-dev
Download the project through the zip package and extract it to a directory where the docker command will be executed. The structure of the directory is the same as the directory structure on github, so it is not shown here.

build image

Execute the following command to build an image. During the execution process, special attention should be paid to the fact that there is a "." at the end of the command, otherwise an error will occur:

docker build -t ethereum/client-go:test .

boot image

Execute the following command to start the mirror:

docker run --name geth -d -p 8110:8110  ethereum/client-go:test

Here you need to pay attention to the port you are using.
So far, a dev environment has been built, and three accounts have been initialized with a certain balance.

Configuration file parsing

genesis.json file:

{
  "nonce": "0x00006d6f7264656e",
  "difficulty": "0x20000",
  "mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
  "coinbase": "0xde1e758511a7c67e7db93d1c23c1060a21db4615",
  "timestamp": "0x00",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "0x",
  "gasLimit": "0x2FEFD8",
  "alloc": {
    "de1e758511a7c67e7db93d1c23c1060a21db4615": {
      "balance": "1000"
    },
    "27dc8de9e9a1cb673543bd5fce89e83af09e228f": {
      "balance": "1100"
    },
    "d64a66c28a6ae5150af5e7c34696502793b91ae7": {
      "balance": "900"
    }
  }
}

This file is the configuration genesis block file. Three accounts were initialized with amounts of 1000, 1100 and 900. Among them, the account that is initialized to 1000 is the miner's reward receiving account. As mining will continue to increase, it may not be this balance when you see it.

Let's take a brief look at the content of the Dockerfile file. In fact, it is very simple, that is, cp the written configuration file to the specified location of the docker container. Special attention should be paid to the port number, which can be modified according to your own needs. For other content, please read the analysis by yourself.

FROM ethereum/client-go

# # our own custom bult geth that mines really fast
# COPY geth /usr/bin/geth

# script that invokes with all those
# command line options
COPY rungeth.docker /usr/bin/rungeth

# these two files and directory of geth state belong together and must be
# kept in sync if changes  are ever made
# Note we are taking advantage of Docker's copy-on-mount feature
COPY geth.password /root/geth.password
COPY genesis.json  /root/genesis.json
COPY ethereum /root/.ethereum

ENTRYPOINT []
ENTRYPOINT ["/usr/bin/rungeth"]

# RUN ["/usr/bin/rungeth"]

# use non-standard ports so don't accidently connect to real servers
# XXX Docker inheritance doesn't override, it extends the port      list...
EXPOSE 8110
EXPOSE 30310
EXPOSE 6110

Method Two

This method was discovered by myself, and it can be used after verification.
This method is very simple, just add the "--dev" parameter after executing the normal start container command. However, this method will not create a batch of initialized accounts like the above method, but you can mine and trade by yourself, and easily obtain accounts of different amounts.

docker run -td -m 512M --memory-swap -1 -p 8545:8545 -p 30303:30303 -v /mnt/docker/dev:/root/.ethereum --name gethDev  ethereum/client-go  --rpcapi "db,eth,net,web3,personal,admin,miner" --rpc --rpcaddr "0.0.0.0" --cache=512 --dev

The above is the startup command after I adjusted it when I started it.

postscript

This blog is written here. If you have any questions, please leave a message to communicate. I am also in the exploratory stage. It is inevitable that there are omissions and superficialities. Follow the blog and make progress together.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325356996&siteId=291194637