2

我想用 Docker 创建私有以太坊网络。我已经准备好了 genesis 文件,所以我需要geth init genesis.json然后像geth --mine .... 我可以用脚本来做(比如这里:https ://github.com/vertigobr/ethereum/blob/master/runminer.sh#L5和https://github.com/vertigobr/ethereum/blob/master/runnode。 sh#L23 ):

if [ ! -d $DATA_ROOT/keystore ]; then
    echo "$DATA_ROOT/keystore not found, running 'geth init'..."
    docker run --rm \
        -v $DATA_ROOT:/root/.ethereum \
        -v $(pwd)/genesis.json:/opt/genesis.json \
        $IMGNAME init /opt/genesis.json
    echo "...done!"
fi
echo "Running new container $CONTAINER_NAME..."
docker run $DETACH_FLAG --name $CONTAINER_NAME \
    --network ethereum \
    -v $DATA_ROOT:/root/.ethereum \
    -v $DATA_HASH:/root/.ethash \
    -v $(pwd)/genesis.json:/opt/genesis.json \
    $RPC_PORTMAP \
    $IMGNAME --bootnodes=$BOOTNODE_URL $RPC_ARG --cache=512 --verbosity=4 --maxpeers=3 ${@:2}

由于这似乎是两步过程,我如何使用 Docker-compose 来完成?

如果我覆盖command:挖矿服务,我应该写什么?如果我只写geth init,那么它不会开始挖掘。如果我尝试加入并写command: init genesis.json --mine ...它会很痛:

version: "3"

services:
  eth_miner:
    image: ethereum/client-go:v1.7.3
    ports:
      - "8545:8545"
    volumes:
      - ${DATA_ROOT}:/root/.ethereum
      - ${GENESIS_FILE}:/opt/genesis.json
    command: init /opt/genesis.json --rpc --rpcaddr=0.0.0.0 --rpcapi=db,eth,net,web3,personal --rpccorsdomain "*" --nodiscover --cache=512 --verbosity=4 --mine --minerthreads=3 --networkid 15 --etherbase="${ETHERBASE}" --gasprice=${GASPRICE}

日志:

Attaching to 7adbb760_eth_miner_1
eth_miner_1  | Incorrect Usage: flag provided but not defined: -rpc
eth_miner_1  | 
eth_miner_1  | init [command options] [arguments...]
eth_miner_1  | 
eth_miner_1  | The init command initializes a new genesis block and definition for the network.
eth_miner_1  | This is a destructive action and changes the network in which you will be
eth_miner_1  | participating.
eth_miner_1  | 
eth_miner_1  | It expects the genesis file as argument.
eth_miner_1  | 
eth_miner_1  | ETHEREUM OPTIONS:
eth_miner_1  |   --datadir "/root/.ethereum"  Data directory for the databases and keystore
eth_miner_1  | 
eth_miner_1  | DEPRECATED OPTIONS:
eth_miner_1  |   --light  Enable light client mode
eth_miner_1  | 
eth_miner_1  | flag provided but not defined: -rpc
7adbb760_eth_miner_1 exited with code 1
4

1 回答 1

6

您最好的选择是创建一个执行初始化然后运行 ​​geth 的 shell 脚本,应该是这样的:

#!/bin/bash
if [ ! -d /root/.ethereum/keystore ]; then
    echo "/root/.ethereum/keystore not found, running 'geth init'..."
    geth init /opt/genesis.json
    echo "...done!"
fi

geth "$@"

和 docker-compose.yaml:

version: "3"

services:
  eth_miner:
    image: ethereum/client-go:v1.7.3
    ports:
      - "8545:8545"
    volumes:
      - ${DATA_ROOT}:/root/.ethereum
      - ${GENESIS_FILE}:/opt/genesis.json
      - ./init-script.sh:/root/init-script.sh
    entrypoint: /root/init-script.sh
    command: --bootnodes=$BOOTNODE_URL $RPC_ARG --cache=512 --verbosity=4 --maxpeers=3 ${@:2}
于 2018-05-30T07:45:59.697 回答