我想用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
答案 0 :(得分:1)
你最好的选择是创建一个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}