Building an Ethereum private environment based on Docker

1 Ethereum Network

1) Production environment network: real Ethereum environment that consumes ether

2) Test network: a public network development and debugging environment that does not consume ether

3) Private network: a network that only nodes of the private network are allowed to use


2 Execute command and parameter analysis

1) Execute the command

docker run -it -d --name eth-node -p 30303:30303 -p 8545:8545 --network eth-network --ip 172.25.0.10 ethereum/client-go --rpc --rpcaddr "0.0.0.0" --rpcapi "admin,debug,eth,miner,net,personal,shh,txpool,web3" --nodiscover --networkid 15 --fast --cache=512 --dev console 2>>/tmp/eth.log


2) Docker parameters

-it: interactive run mode, -i standard input to the container, -t allocates a virtual terminal

-d: run as a daemon (background)

-p: specify the port number

-P: Randomly assign port numbers

--name: Specify the container name

--network: specify the network connection

--ip: assign ip address


3) Ethereum parameters

--rpc: enable HTTP-RPC service

--rpcaddr: HTTP-RPC service listening interface (default: localhost)

--rpcapi: API provided by HTTP-RPC interface (default: eth, net, web3)

--fast: start Geth in fast sync mode

--cache=512: memory capacity allocation

--dev: development mode

--nodiscover: The node is not discovered by other nodes, allowing manual connections

--networkid: set the isolated network (the main network id is 1)

console: enter the JavaScript console


3 Three ways to build an Ethereum private network (the latest version: Geth 1.8.4)

1) docker run ethereum/client-go --dev parameter

illustrate:

The --dev parameter provides a coinbase account and a certain amount of ether for development, debugging, and testing;

miner.start() starts mining and waits for the transaction "waiting for transaction";

miner.sendTransaction(), mining package transaction, block increase;




2) docker-geth-dev resource

Resource link: https://github.com/pragmaticcoders/docker-geth-dev

Description: Provide running containers, build a private network, and provide account creation and account balance in advance.


Download project file

$ git clone https://github.com/pragmaticcoders/docker-geth-dev.git /docker-geth-dev


Build a custom ethereum image

$ make build


Start the container node

$ make rpc

test node running

$ make test

Note: In the current latest version of Geth 1.8, there is a problem with creating an Ethereum private development environment according to the instructions, and the container fails to run successfully.


3) Dockerfile custom image

Description: Package the custom ethereum image by writing the genesis file genesis.json.

Step 1: Dockerfile (custom)

Step 2: Init.sh script file (custom)

Step 3: Genesis.json file (custom)

{
  "config": {
        "chainId": 15,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "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"
    }
  }
}

步骤4:创建镜像

$ docker build -t ethereum/client-go:1.0 .


步骤5:启动容器

$ docker run -d --name eth-node -p 30303:30303 -p 8545:8545 --net eth-network --ip 172.25.0.10 ethereum/client-go:1.0

步骤6:查看账户信息

curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' 172.25.0.10:8545


4 参考

https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options

https://github.com/ethereum/go-ethereum/wiki/Private-network




Guess you like

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