docker中什么是geth

docker中,Geth是指由以太坊基金会提供的官方客户端软件,用Go编程语言编写的;Geth客户端提供了一个交互式命令控制台,该命令控制台中包含了以太坊的各种功能。

docker中什么是geth

本教程操作环境:linux5.9.8系统、docker-1.13.1版、Dell G3电脑。

什么是geth

Geth是由以太坊基金会提供的官方客户端软件,用Go编程语言编写的。Geth提供了一个交互式命令控制台,该命令控制台中包含了以太坊的各种功能(API)。全名go-ethereum。

docker部署geth客户端

一 安装docker

自行百度

二 把上面这个镜像pull下来,pull最新的即可

docker pull ethereum/client-go

三 先说说docker run的参数

因为官方镜像如果直接启动会默认为geth,直接同步主网络,我们肯定是不希望他直接同步的,命令如下

docker run -d -it --name=node0  -u root -p 8545:8545 -p 30303:30303 -v E:eth:/root --privileged=true --entrypoint /root/a.sh ethereum/client-go

-v 代表将本地文件挂载上去

–privileged 真正的sudo权限

–entrypoint 入口脚本,如果存在会覆盖掉dockerfile里的声明

我在这个脚本里选择了把私链初始化,如何初始化可以看官方教程和我之前的文章

我的脚本

#!/bin/sh #初始化创世区块 geth -datadir  /root/data init /root/gener.json  if [  $# -lt 1 ]; then    exec "/bin/sh" else   exec /bin/sh -c "$@" fi

四 启动私链

这里要注意一个问题,就是启动的参数又又又更新了

以前是–rpc –rpcapi,现在换成了–http balabala

HTTP based JSON-RPC API options:

  • –http Enable the HTTP-RPC server
  • –http.addr HTTP-RPC server listening interface (default: localhost)
  • –http.port HTTP-RPC server listening port (default: 8545)
  • –http.api API’s offered over the HTTP-RPC interface (default: eth,net,web3)
  • –http.corsdomain Comma separated list of domains from which to accept cross origin requests (browser enforced)
  • –ws Enable the WS-RPC server
  • –ws.addr WS-RPC server listening interface (default: localhost)
  • –ws.port WS-RPC server listening port (default: 8546)
  • –ws.api API’s offered over the WS-RPC interface (default: eth,net,web3)
  • –ws.origins Origins from which to accept websockets requests
  • –ipcdisable Disable the IPC-RPC server
  • –ipcapi API’s offered over the IPC-RPC interface (default: admin,debug,eth,miner,net,personal,shh,txpool,web3)
  • –ipcpath Filename for IPC socket/pipe within the datadir (explicit paths escape it)

所以现在的启动命令就成了

geth --networkid 666 --http --http.addr=0.0.0.0 --http.port=8545 --http.api "web3,eth,debug,personal,net" --http.corsdomain "*" --allow-insecure-unlock --datadir /root/data  console 2>>geth.log

接下来就该干什么干什么了

用web3连接测试一下

var Web3 = require('web3'); var Tx = require('ethereumjs-tx').Transaction; if (typeof web3 !== 'undefined') {     web3 = new Web3(web3.currentProvider);     console.log("1"+web3.version)   } else {     // set the provider you want from Web3.providers     web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8545'));     console.log(web3.version)   }

推荐学习:《docker视频教程

以上就是

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享