最好的选择是创建一个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}