Access IPFS running on host machine 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(‘’, 5001)

EDIT: I figured out that from mac I should use
api = ipfsapi.connect(‘’,5001)
and it works fine.
What exactly is “” ?
How can I connect from linux machines?


quick question : could you share your docker ps result please ?

Here it is:

a9b384196a2c ubuntu “/bin/bash” 9 hours ago Up 8 hours testipfs

and I run the container like this:

docker run -it --name testipfs ubuntu

I also tried with docker run -it -p 5001:5001 --name testubuntu ubuntu

1 Like

maybe you can try with image there are Docker file please publish 5001 4001 4001/udp 8080 8081


1 Like

I would like to my own image…

don’t you just need to connect from ‘’, 5001 (instead of when running within a container. I think that should work on both Mac and Linux

Here’s my Docker file and and ipfs config file:

I could be wrong, but isn’t it best not to expose 5001. Usually 5001 is only needed internally within the Docker container to run CLI commands.

My understanding is that you would only want to expose it if you wanted to be able to remotely control the CLI

See Cannot transfer between two firewalled machines

So 5001 is for controlling the ipfs daemon you mean?

@jeffreycwitt I will try

‘’, 5001

that’s my understanding.

But since 5001 is only needed inside the container should work

But if you want to access 4001 and 8080 outside the container you should set the config to