2
from web3 import Web3

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

I have the above script Dockerized and I'm trying to connect to geth.ipc on local host and I can't seem to connect to it.

Here is how I run Docker:

docker run --mount type=bind,source=$HOME/Library/Ethereum,target=/Ethereum container1

I've verified that geth.ipc exists in /Ethereum directory but cannot seem to connect to it. Is there a way to do it?

The question might be related to this and here is my original question https://stackoverflow.com/questions/52715141/how-to-make-a-docker-container-talk-to-geth-on-local-host

0

Use host.docker.internal

This works on Docker for Mac and Docker for Windows.

If you're on Linux, things get more complex. Please take a look at https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach

  • This approach doesn't seem to work. I'll submit an issue with geth – Eric Lim Oct 14 '18 at 19:23
0

If you mount the folder containing the IPC file rather than the file directly it will work.

  • Can permission cause a problem ? I.e. will the user that is running docker instance, have access to socket created by user on localhost ? – Shamit Verma Dec 5 '18 at 14:46
  • If you mount it via -v flag then there shouldn't be any permission issues. – Daniel Dec 5 '18 at 15:43
0

geth.ipc represent an "Unix Domain Socket".

This article has steps to expose suck a socket to docker container.

https://www.jujens.eu/posts/en/2017/Feb/15/docker-unix-socket/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.