在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視頻教程》
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END
喜歡就支持一下吧
相關推薦