hey I am working on a project using docker compose. I need one image to use the other images' 5001 port and its not working... if I run this outside a docker container using standard version of these services it seems to work fine.
here is my docker compose file:
version: "3"
services:
web:
image: fulton/pegasus
ports:
- 8000:8000
depends_on:
- ipfs
ipfs:
image: ipfs/go-ipfs
ports:
- 5001:5001
- 8080:8080
and here is the code that is giving the errors (its kotlin)
val response =
Unirest.post("http://0.0.0.0:5001/api/v0/add?chunker=size-262144&hash=sha2-256&inline-limit=32")
.field(file_name,file_data)
.asString()
I am pretty new to compose and any help will be awesome :]
Top comments (9)
You need the links directive on the container that will access the other one.
For example
Also, you might wanna try 127.0.0.1 instead of 0.0.0.0.
Links have been deprecated for quite some time and networks are the recommended approach:
docs.docker.com/compose/compose-fi...
Good to know. I've never used it until I had to use docker on Windows, for some reason, it's the only way that the network would work.
yeah, I'm aware a lot of people experience problems with docker on windows, I've never really got into any problems other than slowness compared to linux. it's actually quite stable for me.
Linux definitely is the best option
Like Carlos mentioned, you should just be able to reference it like this:
Docker compose automatically creates a network for you, in which you can reference other containers by using their name. These names are saved in /etc/hosts inside of the containers, so they automatically resolve to the correct IP address.
you should create a network for the compose, name each service, and access the services by name and you don't even need to expose the ports on the host.
even without changes, in your case, if you change the url to ipfs:5001 it will work.
ps: you should really read-up on docker networking in general, because it's just by chance that it works in your 0.0.0.0 scenario anyway
thank you sir, it works :)
can we see domain name in a internal docker network ??