如何在 docker-compose 中从一个容器连接到另一个容器?
How to connect from one container to another in docker-compose?
我正在尝试 运行 8 个容器。 4个节点和4个abci节点。这是我的 docker-compose 文件
想法是将每个节点连接到它的 abci 节点。
所有节点之间共享的配置文件位于目录中名为 build 的文件夹中。
version: '3'
services:
node0:
container_name: node0
image: "tendermintnode"
ports:
- "26656-26657:26656-26657"
environment:
- ID=0
- LOG=$${LOG:-tendermint.log}
build:
context: .
dockerfile: abci.Dockerfile
volumes:
- ./build:/tendermint
command: tendermint node --proxy_app=tcp://abci0:26658 --home "./tendermint/node0" --consensus.create_empty_blocks=false
depends_on:
- abci0
networks:
localnet:
ipv4_address: 192.167.10.2
node1:
.
node2:
node3:
.
abci0:
container_name: abci0
image: "abcinode"
build:
context: .
dockerfile: abci.Dockerfile
command: python3 vimana/tendermint/app.py
networks:
localnet:
ipv4_address: 192.167.10.6
abci1:
.
abci2:
.
abci3:
.
networks:
.
本来应该开始互相发送请求的。但它却给出了。
abci1 | INFO ABCIServer started on port: 26658
abci0 | INFO ABCIServer started on port: 26658
.
.
.
node0 | E[20016-01-20|19:50:10.519] Dialing failed module=pex addr=7ab8dbd0213ba49aaba13bb7d9396072ba4c4496@192.167.10.5:26656 err="dial tcp 192.167.10.5:26656: connect: connection refused" attempts=0
node0 | E[20016-01-20|19:50:10.657] Dialing failed module=pex addr=ba1ee154e395db646cc54c6fd2a9d0f8f9f98bf1@192.167.10.3:26656 err="dial tcp 192.167.10.3:26656: i/o timeout" attempts=0
.
.
.
node2 | I[20016-01-20|19:50:12.576] Started node module=main nodeInfo="{ProtocolVersion:{P2P:5 Block:8 App:0} ID_:01723b064d72fdbe356911652e1f078fa3c5efd5 ListenAddr:tcp://0.0.0.0:26656 Network:chain-EFXD56 Version:0.27.3 Channels:4020212223303800 Moniker:asura Other:{TxIndex:on RPCAddress:tcp://0.0.0.0:26657}}"
node3 | E[20016-01-20|19:50:40.625] Dialing failed module=pex addr=7ab8dbd0213ba49aaba13bb7d9396072ba4c4496@192.167.10.5:26656 err="self ID<7ab8dbd0213ba49aaba13bb7d9396072ba4c4496>" attempts=0
node1 | E[20016-01-20|19:50:41.751] Dialing failed module=pex addr=ba1ee154e395db646cc54c6fd2a9d0f8f9f98bf1@192.167.10.3:26656 err="self ID<ba1ee154e395db646cc54c6fd2a9d0f8f9f98bf1>" attempts=0
node2 | E[20016-01-20|19:50:42.581] Dialing failed module=pex addr=01723b064d72fdbe356911652e1f078fa3c5efd5@192.167.10.4:26656 err="self ID<01723b064d72fdbe356911652e1f078fa3c5efd5>" attempts=0
node0 | E[20016-01-20|19:51:09.660] Dialing failed module=pex addr=753c2e8a68b459816d598b49a0db107f64777fc5@192.167.10.2:26656 err="self ID<753c2e8a68b459816d598b49a0db107f64777fc5>" attempts=0
node0 | E[20016-01-20|19:53:37.353] Error on broadcastTxCommit module=rpc err="Timed out waiting for tx to be included in a block"
如您所见,abci 容器运行良好。但是连接被拒绝了。
基本上,除了像下面这样将相关的容器定义留在同一网络区域之外,您什么都不用做,并且您不必提供特定的 IP 地址(如果您真的不需要。)。
version: "3"
services:
node0:
image: ...
networks:
- abci0_net
node1:
image: ...
networks:
- abci1_net
node2:
image: ...
networks:
- abci2_net
abci0:
image: ...
networks:
- abci0_net
abci1:
image: ...
networks:
- abci1_net
abci2:
image: ...
networks:
- abci2_net
networks:
abci0_net:
driver: bridge
abci1_net:
driver: bridge
abci2_net:
driver: bridge
通过配置,只有配对的机器可以互相访问。
求解答的人,PRhttps://github.com/tendermint/tendermint/pull/3195/files前几天被合并开发
node0:
container_name: node0
image: "tendermint/localnode"
ports:
- "26656-26657:26656-26657"
environment:
- ID=0
- LOG=$${LOG:-tendermint.log}
volumes:
- ./build:/tendermint:Z
command: node --proxy_app=tcp://abci0:26658
networks:
localnet:
ipv4_address: 192.167.10.2
abci0:
container_name: abci0
image: "abci-image"
build:
context: .
dockerfile: abci.Dockerfile
command: <insert command to run your abci application>
networks:
localnet:
ipv4_address: 192.167.10.6
networks:
localnet:
driver: bridge
ipam:
driver: default
config:
-
subnet: 192.167.10.0/16
我正在尝试 运行 8 个容器。 4个节点和4个abci节点。这是我的 docker-compose 文件
想法是将每个节点连接到它的 abci 节点。 所有节点之间共享的配置文件位于目录中名为 build 的文件夹中。
version: '3'
services:
node0:
container_name: node0
image: "tendermintnode"
ports:
- "26656-26657:26656-26657"
environment:
- ID=0
- LOG=$${LOG:-tendermint.log}
build:
context: .
dockerfile: abci.Dockerfile
volumes:
- ./build:/tendermint
command: tendermint node --proxy_app=tcp://abci0:26658 --home "./tendermint/node0" --consensus.create_empty_blocks=false
depends_on:
- abci0
networks:
localnet:
ipv4_address: 192.167.10.2
node1:
.
node2:
node3:
.
abci0:
container_name: abci0
image: "abcinode"
build:
context: .
dockerfile: abci.Dockerfile
command: python3 vimana/tendermint/app.py
networks:
localnet:
ipv4_address: 192.167.10.6
abci1:
.
abci2:
.
abci3:
.
networks:
.
本来应该开始互相发送请求的。但它却给出了。
abci1 | INFO ABCIServer started on port: 26658
abci0 | INFO ABCIServer started on port: 26658
.
.
.
node0 | E[20016-01-20|19:50:10.519] Dialing failed module=pex addr=7ab8dbd0213ba49aaba13bb7d9396072ba4c4496@192.167.10.5:26656 err="dial tcp 192.167.10.5:26656: connect: connection refused" attempts=0
node0 | E[20016-01-20|19:50:10.657] Dialing failed module=pex addr=ba1ee154e395db646cc54c6fd2a9d0f8f9f98bf1@192.167.10.3:26656 err="dial tcp 192.167.10.3:26656: i/o timeout" attempts=0
.
.
.
node2 | I[20016-01-20|19:50:12.576] Started node module=main nodeInfo="{ProtocolVersion:{P2P:5 Block:8 App:0} ID_:01723b064d72fdbe356911652e1f078fa3c5efd5 ListenAddr:tcp://0.0.0.0:26656 Network:chain-EFXD56 Version:0.27.3 Channels:4020212223303800 Moniker:asura Other:{TxIndex:on RPCAddress:tcp://0.0.0.0:26657}}"
node3 | E[20016-01-20|19:50:40.625] Dialing failed module=pex addr=7ab8dbd0213ba49aaba13bb7d9396072ba4c4496@192.167.10.5:26656 err="self ID<7ab8dbd0213ba49aaba13bb7d9396072ba4c4496>" attempts=0
node1 | E[20016-01-20|19:50:41.751] Dialing failed module=pex addr=ba1ee154e395db646cc54c6fd2a9d0f8f9f98bf1@192.167.10.3:26656 err="self ID<ba1ee154e395db646cc54c6fd2a9d0f8f9f98bf1>" attempts=0
node2 | E[20016-01-20|19:50:42.581] Dialing failed module=pex addr=01723b064d72fdbe356911652e1f078fa3c5efd5@192.167.10.4:26656 err="self ID<01723b064d72fdbe356911652e1f078fa3c5efd5>" attempts=0
node0 | E[20016-01-20|19:51:09.660] Dialing failed module=pex addr=753c2e8a68b459816d598b49a0db107f64777fc5@192.167.10.2:26656 err="self ID<753c2e8a68b459816d598b49a0db107f64777fc5>" attempts=0
node0 | E[20016-01-20|19:53:37.353] Error on broadcastTxCommit module=rpc err="Timed out waiting for tx to be included in a block"
如您所见,abci 容器运行良好。但是连接被拒绝了。
基本上,除了像下面这样将相关的容器定义留在同一网络区域之外,您什么都不用做,并且您不必提供特定的 IP 地址(如果您真的不需要。)。
version: "3"
services:
node0:
image: ...
networks:
- abci0_net
node1:
image: ...
networks:
- abci1_net
node2:
image: ...
networks:
- abci2_net
abci0:
image: ...
networks:
- abci0_net
abci1:
image: ...
networks:
- abci1_net
abci2:
image: ...
networks:
- abci2_net
networks:
abci0_net:
driver: bridge
abci1_net:
driver: bridge
abci2_net:
driver: bridge
通过配置,只有配对的机器可以互相访问。
求解答的人,PRhttps://github.com/tendermint/tendermint/pull/3195/files前几天被合并开发
node0:
container_name: node0
image: "tendermint/localnode"
ports:
- "26656-26657:26656-26657"
environment:
- ID=0
- LOG=$${LOG:-tendermint.log}
volumes:
- ./build:/tendermint:Z
command: node --proxy_app=tcp://abci0:26658
networks:
localnet:
ipv4_address: 192.167.10.2
abci0:
container_name: abci0
image: "abci-image"
build:
context: .
dockerfile: abci.Dockerfile
command: <insert command to run your abci application>
networks:
localnet:
ipv4_address: 192.167.10.6
networks:
localnet:
driver: bridge
ipam:
driver: default
config:
-
subnet: 192.167.10.0/16