我正在尝试通过 RPC over HTTP 连接到 docker 容器中的 geth 节点。当我从主机连接并在 Python Web 应用程序中使用 URL http://localhost:8545 和 Web3.HTTPProvider 实例时,它工作正常;但是,当我尝试使用服务器服务的 docker-compose 名称 (http://ethereum:8545) 从另一个容器内部进行连接时,我收到以下错误消息:
docker-compose-web-1 | requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: http://ethereum:8545
我的 docker-compose.yml 如下:
services:
web:
image: cramananjaona/minimalapp:0.0.1
ports:
- "8088:8088"
links:
- ethereum
ethereum:
image: cramananjaona/tabouret:0.0.1
ports:
- 8545:8545
- 30303:30303
以太坊的 Dockerfile 是
FROM alpine:latest
RUN apk update
RUN apk add geth
COPY node02 node02
CMD ["geth", "--datadir", "node02", "--port", "30303", "--nodiscover", "--http", "--http.api", "eth,net,web3,admin", "--http.addr", "0.0.0.0", "--networkid", "1900"]
是否需要将特定选项传递给 docker 或 geth 才能使其工作?
您需要告诉 geth 允许来自主机的连接。 与
--http.vhosts=*
CMD ["geth", "--datadir", "node02", "--port", "30303", "--nodiscover", "--http", "--http.api", "eth,net,web3,admin", "--http.addr", "0.0.0.0", "--networkid", "1900", "--http.vhosts", "*"]