频道栏目
首页 > 资讯 > 其他综合 > 正文

以太坊go-ethereum客户端docker安装(二)开发(dev)环境搭建

16-12-26        来源:[db:作者]  
收藏   我要投稿

方法一:利用现有开源

先给大家介绍一个现成的ethereum/client-go:test工具镜像。

构建镜像

执行以下命令,构建镜像,执行的过程中需要特别注意命令最后是有一个“.”的,否则会出现错误:

docker build -t ethereum/client-go:test .

启动镜像

执行以下命令启动镜像:

docker run --name geth -d -p 8110:8110  ethereum/client-go:test

此处需注意自己所使用的端口。
至此一个dev环境搭建完成,其中的三个账户已经被初始化了一定的余额。

配置文件解析

genesis.json文件:

{
  "nonce": "0x00006d6f7264656e",
  "difficulty": "0x20000",
  "mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
  "coinbase": "0xde1e758511a7c67e7db93d1c23c1060a21db4615",
  "timestamp": "0x00",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "0x",
  "gasLimit": "0x2FEFD8",
  "alloc": {
    "de1e758511a7c67e7db93d1c23c1060a21db4615": {
      "balance": "1000"
    },
    "27dc8de9e9a1cb673543bd5fce89e83af09e228f": {
      "balance": "1100"
    },
    "d64a66c28a6ae5150af5e7c34696502793b91ae7": {
      "balance": "900"
    }
  }
}

此文件为配置创世块文件。对三个账户进行了初始化金额,分别为1000,1100和900。其中初始化为1000里的为矿工奖励接收账户,随着挖矿会不断增加,你看到时候可能已经不是这个余额了。

下面再简单看一下Dockerfile文件的内容,其实很简单,就是将写好的配置文件cp到docker容器的指定位置。特别需要留意的是端口号,可根据自己的需要进行修改。其他内容请自行阅读分析。

FROM ethereum/client-go

# # our own custom bult geth that mines really fast
# COPY geth /usr/bin/geth

# script that invokes with all those
# command line options
COPY rungeth.docker /usr/bin/rungeth

# these two files and directory of geth state belong together and must be
# kept in sync if changes  are ever made
# Note we are taking advantage of Docker's copy-on-mount feature
COPY geth.password /root/geth.password
COPY genesis.json  /root/genesis.json
COPY ethereum /root/.ethereum

ENTRYPOINT []
ENTRYPOINT ["/usr/bin/rungeth"]

# RUN ["/usr/bin/rungeth"]

# use non-standard ports so don't accidently connect to real servers
# XXX Docker inheritance doesn't override, it extends the port      list...
EXPOSE 8110
EXPOSE 30310
EXPOSE 6110

方法二

此方法为本人自行探索得出,经验证可以使用。
此方法非常简单,只需在执行正常的启动容器命令后面添加“–dev”参数即可。不过此方法不会像上面方法那样创建一批初始化账户,不过可以自行挖矿,进行交易,轻易获得不同金额的账户。

docker run -td -m 512M --memory-swap -1 -p 8545:8545 -p 30303:30303 -v /mnt/docker/dev:/root/.ethereum --name gethDev  ethereum/client-go  --rpcapi "db,eth,net,web3,personal,admin,miner" --rpc --rpcaddr "0.0.0.0" --cache=512 --dev

以上为本人启动时调整之后的启动命令。

相关TAG标签
上一篇:网络编程:windows平台下销毁线程的四种方法
下一篇:知识库--Server + Service
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站