Access IPFS running on localhost from docker container

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)

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…

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.

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

Then what’s the host’s ip address?

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.

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.

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

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