代码之家  ›  专栏  ›  技术社区  ›  4ntoine

如何使用docker compose进行geth init和geth挖掘?

  •  0
  • 4ntoine  · 技术社区  · 7 年前

    我想用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组成?

    如果我超驰 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
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Ignacio Millán    7 年前

    最好的选择是创建一个shell脚本,该脚本执行初始化,然后运行geth,应该如下所示:

    #!/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}
    
    推荐文章