Docker Community Forums

Share and learn in the Docker community.

Access IPFS running on localhost from docker container


(Bunjee) #1

Does anyone have experience how to access IPFS from a docker container using python api (ipfsapi) ? It seems that I cannot connect to localhost, where IPFS is running from the docker container.
This is the command to connect:
api = ipfsapi.connect(‘127.0.0.1’, 5001)


(Sam) #2

localhost is inside the container… as it has its OWN UNIQUE IP address (different from the host)…

you need the docker HOST IP address there…


(Bunjee) #3

On mac I tried this and it works:

api = ipfsapi.connect(‘docker.for.mac.host.internal’,5001)

Running this command inside the docker container I get an IP. Is the one of the host?

/sbin/ip route|awk ‘/default/ { print $3 }’

I used the result in the connect but still I have errors.


(Sam) #4

that should be the ip address of the gateway, not the host on the other side


(Bunjee) #5

Then what’s the host’s ip address?


(Sam) #6

on the host , do ip addr, and use the ip address of the appropriate ethernet adapter, just like always.

then when you start the container

docker run -d --add-host host_name:host_ip image_name

then u can use the host_name string to connect back to the host side of the application.

the container cannot discover it.


(David Maze) #7

You said it yourself above: the docker.for.mac.host.internal DNS name reaches the host (assuming, of course, you’re on a pretty current Docker for Mac). You don’t need to know what specific IP address it has.


(Bunjee) #8

@dmaze yes, this is for mac only as I understood and it works fine. What about linux for example?


(Sam) #9

my example was for linux (or mac without using the previous info)