我想用 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