1.3开启你的 Node & Setup

优质
小牛编辑
124浏览
2023-12-01

如果你还没有安装docker, 可以在这下载:: https://www.docker.com/community-edition

Step 1:获取 docker image

下面的命令会下载包含编译好软件的Ubuntu镜像.

docker pull eosio/eos:v1.4.2

Step 2:引导 Node 和 Wallet

docker run --name eosio \
  --publish 7777:7777 \
  --publish 127.0.0.1:5555:5555 \
  --volume /Users/zhong/coding/CLion/contracts:/Users/zhong/coding/CLion/contracts \
  --detach \
  eosio/eos:v1.4.2 \
  /bin/bash -c \
  "keosd --http-server-address=0.0.0.0:5555 & \
  exec nodeos -e -p eosio \
  --plugin eosio::producer_plugin \
  --plugin eosio::chain_api_plugin \
  --plugin eosio::history_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:7777 \
  --access-control-allow-origin=* \
  --contracts-console \
  --http-validate-host=false \
  --filter-on='*'"

这些配置是为了实现:

  1. 将7777和5555端口转发到宿主机
  2. 将宿主机的工作卷声明为docker容器中的别称
  3. 在bash中运行Nodeos的启动命令. 这一命令加载了所有基础插件,配置了服务器地址,允许了CORS以及添加了合约debugging.
  4. 运行没有约束的CORS(*)

在上面的配置中,CORS授权给了*, 这样设置只是为了开发目的,你永远不要在一个公共环境使用该配置.

Step 3: 验证安装

Step 3.1: 验证Nodeos是Producing Blocks

运行以下命令(查看名称为eosio的容器的logs,看最后10条):

docker logs --tail 10 eosio

应该看到如下的内容:

1929001ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366974ce4e2a... #13929 @ 2018-05-23T16:32:09.000 signed by eosio [trxs: 0, lib: 13928, confirmed: 0]
1929502ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366aea085023... #13930 @ 2018-05-23T16:32:09.500 signed by eosio [trxs: 0, lib: 13929, confirmed: 0]
1930002ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366b7f074fdd... #13931 @ 2018-05-23T16:32:10.000 signed by eosio [trxs: 0, lib: 13930, confirmed: 0]
1930501ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366cd8222adb... #13932 @ 2018-05-23T16:32:10.500 signed by eosio [trxs: 0, lib: 13931, confirmed: 0]
1931002ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366d5c1ec38d... #13933 @ 2018-05-23T16:32:11.000 signed by eosio [trxs: 0, lib: 13932, confirmed: 0]
1931501ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366e45c1f235... #13934 @ 2018-05-23T16:32:11.500 signed by eosio [trxs: 0, lib: 13933, confirmed: 0]
1932001ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000366f98adb324... #13935 @ 2018-05-23T16:32:12.000 signed by eosio [trxs: 0, lib: 13934, confirmed: 0]
1932501ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 00003670a0f01daa... #13936 @ 2018-05-23T16:32:12.500 signed by eosio [trxs: 0, lib: 13935, confirmed: 0]
1933001ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 00003671e8b36e1e... #13937 @ 2018-05-23T16:32:13.000 signed by eosio [trxs: 0, lib: 13936, confirmed: 0]
1933501ms thread-0   producer_plugin.cpp:585       block_production_loo ] Produced block 0000367257fe1623... #13938 @ 2018-05-23T16:32:13.500 signed by eosio [trxs: 0, lib: 13937, confirmed: 0]

Step 3.2: 检查Wallet

打开shell,执行命令进入eosio容器,并执行它的bash:

docker exec -it eosio bash

现在你位于eosio容器内了,运行以下命令:

cleos --wallet-url http://127.0.0.1:5555 wallet list

你会看到:

Wallets:
[]

现在退出容器的shell回到主机:

exit

现在keosd正确运行了,输入exit来退出keosdshell.现在开始,你不需要再使用bash进到containers,你将在你的本地系统执行命令.

Step 3.3: 检查 Nodeos endpoints

通过以下方式检查RPC API是否正确执行.访问 http://localhost:7777/v1/chain/get_info 或在主机使用以下命令:

curl http://localhost:7777/v1/chain/get_info

Step 4: 生成Cleos的别称

你不想在每次想和Nodeos 或 Keosd交互的时候都进入到Docker container的bash中,一个解决方案是声明一个alias.

在终端执行下面的命令创建一个临时alias.如果想将其变为永久的alias,在Linux系统中将其加到.bash_rc,如果使用Mac OS将其加到.profile.

alias cleos='docker exec -it eosio /opt/eosio/bin/cleos --url http://127.0.0.1:7777 --wallet-url http://127.0.0.1:5555'

(译者将其声明在了~/.bash_profile下, 编辑保存后使用source使其生效)

Step 5: 常用的Docker命令

Start/Stop Container

docker start eosio
docker stop eosio

Bash

docker exec -it eosio bash

Remove the EOSIO Container

docker rm eosio