如何使 Docker 容器与本地主机上的 geth 通信

How to make a Docker container talk to geth on local host

我有一个使用 web3 Dockerized 的简单 python 脚本,我正在尝试连接到本地主机上的 geth.ipc,但我似乎无法连接到它。有办法吗?

Python:

from web3 import Web3

web3 = Web3(Web3.IPCProvider("/Ethereum/geth.ipc"))
print(f'IPC connected: {web3.isConnected()}')  # want to return True

我正在安装我的 $HOME/Library/Ethereum/geth.ipc -> /Ethereum/geth.ipc

如果您挂载包含 IPC 文件的文件夹而不是直接挂载该文件,它将起作用。