首頁 > 軟體

使用Docker安裝EOS

2020-06-16 16:44:26

前言

接上一篇通過eosio_build.sh指令碼安裝EOS,其實EOS官方更推薦我們使用Docker來安裝(EOS官方已經把編譯好的映象檔案上傳到Docker公共倉庫中),簡單快速,且不用趟編譯過程中的各種依賴坑,所以在此牆裂推薦一下。

一、安裝Docker

參見我的另一篇文章:在Ubuntu下安裝Docker https://www.linuxidc.com/Linux/2018-09/154498.htm

二、安裝EOS

通過Docker安裝EOS,安裝過程非常簡單,只需要從官方拉取一個image即可,安裝時間在10分鐘不等。

1、拉取EOS官方Docker image
$ docker pull eosio/eos-dev
Using default tag: latest
latest: Pulling from eosio/eos-dev
a48c500ed24e: Pulling fs layer
1e1de00ff7e1: Pulling fs layer
0330ca45a200: Pulling fs layer
471db38bcfbf: Pull complete
0b4aba487617: Pull complete
c48089e40a92: Pull complete
6ba3b1cb9ec5: Pull complete
fc42d6567ea7: Pull complete
5aad39598cd9: Pull complete
3289b843cc06: Pull complete
7fce24403a03: Pull complete
693e3de53a75: Pull complete
3eba792bc608: Pull complete
beb224e3e4ff: Pull complete
8be9106d93b3: Pull complete
e68cf64b358f: Pull complete
678c68b82b10: Pull complete
c0fbf552019c: Pull complete
e46f8cadc969: Pull complete
c5bde327188d: Pull complete
Digest: sha256:9994635121c24a82f0028e716941c65908449e2a3e4b5705b14d5642afa3accd
Status: Downloaded newer image for eosio/eos-dev:latest

2、啟動EOSIO節點
$ sudo docker run --rm --name eosio -d -p 8888:8888 -p 9876:9876 -v /tmp/work:/work -v /tmp/eosio/data:/mnt/dev/data -v /tmp/eosio/config:/mnt/dev/config eosio/eos-dev  /bin/bash -c "nodeos -e -p eosio --plugin eosio::wallet_api_plugin --plugin eosio::wallet_plugin --plugin eosio::producer_plugin --plugin eosio::history_plugin --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --plugin eosio::http_plugin -d /mnt/dev/data --config-dir /mnt/dev/config --http-server-address=0.0.0.0:8888 --access-control-allow-origin=* --contracts-console"

啟動正常情況下,返回一個容器ID:
2e1a3574dd2908645843152e5d561af53f3ffa777a99d6ecdd152f5a91230f6f

三、驗證節點通訊

1、檢查節點是否已經正常工作:
$ sudo docker logs --tail 10 eosio


正常情況下輸出的內容應該類似於這樣:
212500ms thread-0  producer_plugin.cpp:1087      produce_block        ] Produced block 000000ac1a243dd1... #172 @ 2018-07-05T04:03:32.500 signed by eosio [trxs: 0, lib: 171, confirmed: 0]
213000ms thread-0  producer_plugin.cpp:1087      produce_block        ] Produced block 000000ad12ef4cd0... #173 @ 2018-07-05T04:03:33.000 signed by eosio [trxs: 0, lib: 172, confirmed: 0]
213500ms thread-0  producer_plugin.cpp:1087      produce_block        ] Produced block 000000aef4292764... #174 @ 2018-07-05T04:03:33.500 signed by eosio [trxs: 0, lib: 173, confirmed: 0]
214000ms thread-0  producer_plugin.cpp:1087      produce_block        ] Produced block 000000af2bf08a6b... #175 @ 2018-07-05T04:03:34.000 signed by eosio [trxs: 0, lib: 174, confirmed: 0]
214500ms thread-0  producer_plugin.cpp:1087      produce_block        ] Produced block 000000b0fb442f21... #176 @ 2018-07-05T04:03:34.500 signed by eosio [trxs: 0, lib: 175, confirmed: 0]
215000ms thread-0  producer_plugin.cpp:1087      produce_block        ] Produced block 000000b18f90a938... #177 @ 2018-07-05T04:03:35.000 signed by eosio [trxs: 0, lib: 176, confirmed: 0]
215500ms thread-0  producer_plugin.cpp:1087      produce_block        ] Produced block 000000b25c380b9c... #178 @ 2018-07-05T04:03:35.500 signed by eosio [trxs: 0, lib: 177, confirmed: 0]
216000ms thread-0  producer_plugin.cpp:1087      produce_block        ] Produced block 000000b33b225011... #179 @ 2018-07-05T04:03:36.000 signed by eosio [trxs: 0, lib: 178, confirmed: 0]
216500ms thread-0  producer_plugin.cpp:1087      produce_block        ] Produced block 000000b432badfcf... #180 @ 2018-07-05T04:03:36.500 signed by eosio [trxs: 0, lib: 179, confirmed: 0]
217000ms thread-0  producer_plugin.cpp:1087      produce_block        ] Produced block 000000b5b315cf60... #181 @ 2018-07-05T04:03:37.000 signed by eosio [trxs: 0, lib: 180, confirmed: 0]

2、在瀏覽器中檢視節點資訊:
 在瀏覽器位址列存取 http://localhost:8888/v1/chain/get_info,檢查RPC介面是否正常工作,正常情況下會顯示:
{
"server_version": "5875549c",
"chain_id": "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f",
"head_block_num": 2233,
"last_irreversible_block_num": 2232,
"last_irreversible_block_id": "000008b872290cc75b8cb68b836a82ff87a1cc39b75f88341765f68bc925a623",
"head_block_id": "000008b9c9c9c11ee3e4c95613c971861788f7e80a82e20bcad0c2ef622aa7be",
"head_block_time": "2018-07-05T04:20:43.000",
"head_block_producer": "eosio",
"virtual_block_cpu_limit": 1861596,
"virtual_block_net_limit": 9777935,
"block_cpu_limit": 199900,
"block_net_limit": 1048576
}

以上資訊我們還可以通過cleos get info命令檢視到。

至此,我們就在Docker容器中成功地執行了一個EOS節點區塊鏈!

四、用戶端設定

1、在docker下使用cleos用戶端,我們需要以Docker的命令方式來執行,且需要帶命令的完整路徑
 ,如/opt/eosio/bin/cleos,為了後續操作方便,我們給cleos命令設定一下別名:
alias cleos='docker exec eosio /opt/eosio/bin/cleos --wallet-url http://localhost:8888'

我們試著在終端測試一下是否生效:
$ cleos --help

看到命令的相關引數資訊就說明已經可以執行生效了。

2、關閉節點執行
$ docker stop eosio

之前使用eosio_build.sh指令碼的安裝方式時,只能粗暴的按Ctrl+C中斷節點,有了Docker後,就能優雅地關閉節點了。

參考:
https://developers.eos.io/eosio-nodeos/docs/docker-quickstart EOS官方開發文件


IT145.com E-mail:sddin#qq.com