EOS Dapp開發(1)-基於Docker的開發環境搭建


隨着EOS主網的上線,相信基於EOS的Dapp開發會越來越多,查閱了很多資料相關的開發資料都不是很多,只能自己摸索,按照網上僅有的幾篇教程,先git clonehttps://github.com/EOSIO/eos –recursive,然后慢慢編譯,然后就陷入了各種報錯、各種奔潰的場景。為什么編譯不報錯的環境都是別人的!!!!。

沒辦法只能另想辦法,突然想到Docker這個神一樣的東西(之前的隨筆里有一篇是redhat 7.2 內網安裝docker),去Docker hub上搜EOS,果然有....https://hub.docker.com/r/eosio/,選取eosio/eos,然后開工,這個鏡像不大,200多M,下載之后

1 docker pull eosio/eos
2 docker images
3 docker.io/eosio/eos              latest              01fdb2b0f454        34 hours ago        245 MB

下載好了,啟動鏡像:

 1 docker run --name nodeos -v /home/docker/dockerdata/eosdata:/opt/eos/bin/data-dir -p 8888:8888 -p 9876:9876 -p10023:22 -t eosio/eos nodeosd.sh
 2 
 3 36039ms thread-0   chain_plugin.cpp:206          plugin_initialize    ] initializing chain plugin
 4 36039ms thread-0   chain_plugin.cpp:381          plugin_initialize    ] Starting up fresh blockchain with default genesis state.
 5 CHAINBASE:   Failed to pin chainbase shared memory (of size 8192 MB) in RAM. Performance degradation is possible.
 6 CHAINBASE:   Failed to pin chainbase shared memory (of size 340 MB) in RAM. Performance degradation is possible.
 7 36065ms thread-0   http_plugin.cpp:285           plugin_initialize    ] configured http to listen on 0.0.0.0:8888
 8 36065ms thread-0   net_plugin.cpp:2840           plugin_initialize    ] Initialize net plugin
 9 36065ms thread-0   net_plugin.cpp:2861           plugin_initialize    ] host: 0.0.0.0 port: 9876 
10 36065ms thread-0   net_plugin.cpp:2933           plugin_initialize    ] my node_id is cd8092582bcd89ffe102968f67e058cefa284d43977d28fee1fac2200b78c8de
11 36066ms thread-0   main.cpp:104                  main                 ] nodeos version 012dc012
12 36066ms thread-0   main.cpp:105                  main                 ] eosio root is /root/.local/share
13 36066ms thread-0   controller.cpp:1180           startup              ] No head block in fork db, perhaps we need to replay
14 36066ms thread-0   controller.cpp:307            initialize_fork_db   ]  Initializing new blockchain with genesis state                  
15 36101ms thread-0   chain_plugin.cpp:436          plugin_startup       ] starting chain in read/write mode
16 36101ms thread-0   chain_plugin.cpp:441          plugin_startup       ] Blockchain started; head block is #1, genesis timestamp is 2018-06-01T12:00:00.000
17 36101ms thread-0   http_plugin.cpp:323           plugin_startup       ] start listening for http requests
18 36101ms thread-0   chain_api_plugin.cpp:75       plugin_startup       ] starting chain_api_plugin
19 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/abi_bin_to_json
20 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/abi_json_to_bin
21 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/get_abi
22 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/get_account
23 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/get_block
24 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/get_block_header_state
25 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/get_code
26 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/get_currency_balance
27 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/get_currency_stats
28 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/get_info
29 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/get_producers
30 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/get_required_keys
31 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/get_table_rows
32 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/push_block
33 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/push_transaction
34 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/chain/push_transactions
35 36101ms thread-0   history_api_plugin.cpp:38     plugin_startup       ] starting history_api_plugin
36 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/history/get_actions
37 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/history/get_controlled_accounts
38 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/history/get_key_accounts
39 36101ms thread-0   http_plugin.cpp:369           add_handler          ] add api url: /v1/history/get_transaction
40 36102ms thread-0   net_plugin.cpp:2945           plugin_startup       ] starting listener, max clients is 25
41 36102ms thread-0   producer_plugin.cpp:577       plugin_startup       ] producer plugin:  plugin_startup() begin
42 36102ms thread-0   producer_plugin.cpp:592       plugin_startup       ] Launching block production for 1 producers at 2018-06-13T11:00:36.102.
43 36102ms thread-0   producer_plugin.cpp:604       plugin_startup       ] producer plugin:  plugin_startup() end

有兩個Failed,我測試下來暫時未發現有什么影響,暫且跳過不管(網上也有人說至少需要8G,這個后續有問題我會再更新處理)。有人反饋界面會卡在這里,其實Ctrl + C退出也沒關系,容器還是會一直運行。

docker exec -it nodeos /bin/bash 進入容器,

ps:通過上述方式進入容器不是很方便,這里提供一種方式給容器安裝ssh服務(雖然不推薦這么做,為了省事還是....)

#進入容器后執行如下代碼

#對於不能上網的需要設置代理的需要將代理兩行放開
#proxy=192.168.1.100:3129 &&\
#export http_proxy=http://${proxy} &&\
echo 'root:root' |chpasswd &&\
apt-get update &&\
apt-get -y install openssh-server &&\
sed -ri 's/^#PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config && \
sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config && \
/etc/init.d/ssh start

 

進入 /opt/eosio/bin,EOS相關的命令都在這里

cd /opt/eosio/bin
ls -rtl
total
98476 -rwxr-xr-x. 1 root root 568 Jun 12 00:00 nodeosd.sh -rwxr-xr-x. 1 root root 2520080 Jun 12 00:01 eosio-s2wasm -rwxr-xr-x. 1 root root 698824 Jun 12 00:01 eosio-wast2wasm -rwxr-xr-x. 1 root root 5652336 Jun 12 00:03 eosio-launcher -rwxr-xr-x. 1 root root 7710032 Jun 12 00:03 keosd -rwxr-xr-x. 1 root root 27580032 Jun 12 00:03 eosio-abigen -rwxr-xr-x. 1 root root 48145016 Jun 12 00:03 nodeos -rwxr-xr-x. 1 root root 8510256 Jun 12 00:03 cleos drwxr-xr-x. 3 root root 4096 Jun 13 11:00 data-dir

核心關注的命令是cleos、nodeos、keosd。

cleos:命令行程序,通過命令行執行相應命令,如錢包、轉賬等操作

 1 Options:
 2   -h,--help                   Print this help message and exit
 3   -u,--url TEXT=http://localhost:8888/
 4                               the http/https URL where nodeos is running
 5   --wallet-url TEXT=http://localhost:8900/
 6                               the http/https URL where keosd is running
 7   -r,--header                 pass specific HTTP header; repeat this option to pass multiple headers
 8   -n,--no-verify              don't verify peer certificate when using HTTPS
 9   -v,--verbose                output verbose actions on error
10   --print-request             print HTTP request to STDERR
11   --print-response            print HTTP response to STDERR
12 
13 Subcommands:
14   version                     Retrieve version information
15   create                      Create various items, on and off the blockchain
16   get                         Retrieve various items and information from the blockchain
17   set                         Set or update blockchain state
18   transfer                    Transfer EOS from account to account
19   net                         Interact with local p2p network connections
20   wallet                      Interact with local wallet
21   sign                        Sign a transaction
22   push                        Push arbitrary transactions to the blockchain
23   multisig                    Multisig contract commands
24   system                      Send eosio.system contract action to the blockchain.

 

 nodes:是一個挖礦的客戶端,啟動之后會開始挖礦,容器啟動命令里nodeosd.sh,就是啟動了一個nodes。

keosd:主要和錢包相關。

 至此基於Docker的Eos環境搭建完畢,下一篇將開始EOS Dapp開發。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM