DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Fulton Browne
Fulton Browne

Posted on

help with docker compose

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
Enter fullscreen mode Exit fullscreen mode

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()
Enter fullscreen mode Exit fullscreen mode

I am pretty new to compose and any help will be awesome :]

Top comments (9)

Collapse
 
coderdood profile image
Marcelus Trojahn

You need the links directive on the container that will access the other one.

For example

services:
  web:
    (...)
    links:
      ipfs

Also, you might wanna try 127.0.0.1 instead of 0.0.0.0.

Collapse
 
cmanique profile image
Carlos Manique Silva

Links have been deprecated for quite some time and networks are the recommended approach:

docs.docker.com/compose/compose-fi...

Collapse
 
coderdood profile image
Marcelus Trojahn

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.

Thread Thread
 
cmanique profile image
Carlos Manique Silva

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.

Thread Thread
 
anditsou profile image
Ítalo Sousa

Linux definitely is the best option

Collapse
 
roelofjanelsinga profile image
Roelof Jan Elsinga • Edited on

Like Carlos mentioned, you should just be able to reference it like this:

http://ipfs:5001

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.

Collapse
 
cmanique profile image
Carlos Manique Silva • Edited on

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

Collapse
 
fultonbrowne profile image
Fulton Browne

thank you sir, it works :)

Collapse
 
zarszz profile image
Ganjar Gingin Tahyudin

can we see domain name in a internal docker network ??

DEV

Thank you.

Β 
Thanks for visiting DEV, we’ve worked really hard to cultivate this great community and would love to have you join us. If you’d like to create an account, you can sign up here.