我正在创建 Dockerfile
以在 ubuntu 容器上运行以太坊节点。
我想在容器中依次运行以下 shell 命令。
geth --datadir /home/ubuntu/eth-dev init /home/ubuntu/eth-dev/genesis.json
geth --networkid 45634 --verbosity 4 --ipcdisable --rpc --port 30301 --rpcport 8545 --rpcaddr 0.0.0.0 console 2>> /home/ubuntu/eth-dev/eth.log
我在 Dockerfile 中的入口点下方创建了我认为不正确的内容。
ENTRYPOINT ["geth", "--datadir /home/ubuntu/eth-dev", "init /home/ubuntu/eth-dev/genesis.json", "--networkid 45634", "--verbosity 4", "--ipcdisable", "--rpc", "--port 30301", "--rpcport 8545", "--rpcaddr 0.0.0.0", "console 2>> /home/ubuntu/eth-dev/eth.log"]
任何人都可以更正上述 shell 命令的 ENTRYPOINT
吗?
最佳答案
将这两个命令放在一个 shell 脚本中,COPY
Dockerfile 中的 shell 脚本,然后使用该 shell 脚本作为入口点。
docker 入口点.sh:
geth --datadir /home/ubuntu/eth-dev init /home/ubuntu/eth-dev/genesis.json
geth --networkid 45634 --verbosity 4 --ipcdisable --rpc --port 30301 --rpcport 8545 --rpcaddr 0.0.0.0 console 2>> /home/ubuntu/eth-dev/eth.log
docker 文件:
COPY docker-entrypoint.sh /usr/bin/docker-entrypoint.sh
ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"]
确保 chmod +x
脚本,在复制之前或在 Dockerfile 中的 RUN
命令中。
关于具有多个参数的 docker 入口点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46336508/