如何`geth初始化`并开始使用Docker构建geth挖掘?(How to `geth init` and start geth mining with Docker

编程入门 行业动态 更新时间:2024-10-11 05:29:07
如何`geth初始化`并开始使用Docker构建geth挖掘?(How to `geth init` and start geth mining with Docker-compose?)

我想用Docker创建私有以太坊网络。 我准备了起源文件,所以我需要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

I want to create private ethereum network with Docker. I've prepared genesis file so i need to geth init genesis.json and then start mining like geth --mine .... I can do it with scripts (like here: https://github.com/vertigobr/ethereum/blob/master/runminer.sh#L5 and 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}

Since it seems to be 2-step process how can i do it with Docker-compose?

If i override command: for mining service, what should i write? If i write just geth init, then it will not start mining. If i try to join and write command: init genesis.json --mine ... it hurts:

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}

log:

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

最满意答案

你最好的选择是创建一个执行初始化并运行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}

Your best option is creating a shell script which do the initialization and then run geth, should be something like this:

#!/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 "$@"

And 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}

更多推荐

本文发布于:2023-07-17 15:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1146373.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   Docker   geth   mining   start

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!