• 技术文章 >运维 >Docker

    docker中什么是geth

    青灯夜游青灯夜游2022-02-21 16:41:37原创85

    在docker中,Geth是指由以太坊基金会提供的官方客户端软件,用Go编程语言编写的;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视频教程

    以上就是docker中什么是geth的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:docker geth
    上一篇:docker集群有什么用 下一篇:docker的优势和不足有哪些
    PHP编程就业班

    相关文章推荐

    • 技术解答之Pipeline整合Docker容器• 基于Docker镜像部署go项目(实例详解)• docker中镜像和容器的区别是什么• 解析docker怎么搭建lnmp环境(php7.4 + nginx )• 带你搞懂怎么基于Docker安装Nginx搭建静态服务器• Docker镜像原理之联合文件系统和分层理解(实例详解)

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网