docker環境のethereumをプライベートで接続する

環境

node1とnode2を接続する

IPアドレスを調べる

% sudo docker inspect ethereum-node-01 | grep \"IPAddress |grep -v \"\"
                    "IPAddress": "172.22.0.2",

% sudo docker inspect ethereum-node-02 | grep \"IPAddress |grep -v \"\"
                    "IPAddress": "172.22.0.3",

※admin.addPeerする際にホスト名ではなく、IPアドレスが必要

疎通を確認

% sudo docker exec -it ethereum-node-01 ping ethereum-node-02
PING ethereum-node-02 (172.22.0.3): 56 data bytes
64 bytes from 172.22.0.3: seq=0 ttl=64 time=0.232 ms
64 bytes from 172.22.0.3: seq=1 ttl=64 time=0.246 ms

% sudo docker exec -it ethereum-node-02 ping ethereum-node-01
PING ethereum-node-01 (172.22.0.2): 56 data bytes
64 bytes from 172.22.0.2: seq=0 ttl=64 time=0.480 ms
64 bytes from 172.22.0.2: seq=1 ttl=64 time=0.203 ms

node02のnodeInfoを取得

% sudo docker exec -it ethereum-node-02 geth attach rpc:http://localhost:8545

> admin.nodeInfo.enode
"enode://cfb24fe963ad802e261619235033e38dea0e0f2de63064bfd494e58fc7bb5fb86d9a8e4bed2d4664b35ded123e33b5f006db08df1333ab4a82bb1ed2ba1d767b@[::]:30303?discport=0"

node01からnode02へ接続

% sudo docker exec -it ethereum-node-01 geth attach rpc:http://localhost:8545

> admin.addPeer("enode://cfb24fe963ad802e261619235033e38dea0e0f2de63064bfd494e58fc7bb5fb86d9a8e4bed2d4664b35ded123e33b5f006db08df1333ab4a82bb1ed2ba1d767b@172.22.0.3:30303?discport=0")
true
※[::]だったところを、node02のIPアドレスに変更する

> admin.peers
[{
    caps: ["eth/62", "eth/63"],
    id: "cfb24fe963ad802e261619235033e38dea0e0f2de63064bfd494e58fc7bb5fb86d9a8e4bed2d4664b35ded123e33b5f006db08df1333ab4a82bb1ed2ba1d767b",
    name: "Geth/v1.8.0-unstable-0662384d/linux-amd64/go1.9.3",
    network: {
      localAddress: "172.22.0.2:35260",
      remoteAddress: "172.22.0.3:30303"
    },
    protocols: {
      eth: {
        difficulty: 278121932,
        head: "0x80c11e45770fa315c24d56469bbf52f7a635d2a404ffee2a19ef90408f625151",
        version: 63
      }
    }
}]

> net.peerCount
1

> eth.blockNumber
2229

node02で接続を確認する

% sudo docker exec -it ethereum-node-02 geth attach rpc:http://localhost:8545

> admin.peers
[{
    caps: ["eth/62", "eth/63"],
    id: "021b697ab806c28ec99aa9dc601308b8b77d6659d8cb7fcde758bb2b1af813f3cc036476ed59e95246e85a5ff7b66ac2d1ec8ef4a9dcceb9bb0a245ff7089af0",
    name: "Geth/v1.8.0-unstable-0662384d/linux-amd64/go1.9.3",
    network: {
      localAddress: "172.22.0.3:30303",
      remoteAddress: "172.22.0.2:35748"
    },
    protocols: {
      eth: {
        difficulty: 433531171,
        head: "0xd1510332bc8cc51396d7b07861ad9d2e6e568da1980684cba917345f649f0ffb",
        version: 63
      }
    }
}]

> net.peerCount
1

> eth.blockNumber
2229
※同期できていれば同じ値になっている

投稿日

カテゴリー:

,

投稿者: