Docker compose doesn't let my images connect with each other

I have a docker compose file that starts two images:

version: '3'
services:
  ganache:
    image: trufflesuite/ganache-cli:latest
    ports:
      - "8545:8545"

  app:
    image: -- my custom image --
    depends_on:
      - ganache
    ...

app contains a small script that connects to ganache-cli via port 8545 and fails to do so if I run this docker composition.

If I run ganache-cli on my machine and run my script it works without an issue. I’m aware that I cannot forward the port to localhost on mac but can I at least somehow connect the docker images with each other so that my custom image can access ganache-cli via localhost:8545 ?

Thanks in advance!

Hi :slight_smile:

Try from your app container, and connect to the ganache like this: ganache:8545 ( since its the service name )

Hi terpz!

Thanks for your response. Using curl from my app container I can indeed access the ganache container with ganache:8545. It also revealed to me that the full name of the container is actually: docker_ganache_1.docker_default:8545

Using that from my application in the app container did let me access the ganache container. Accessing it from the host did not work though, neither with ganache:845 nor with the full domain name. Is that even possible?

Hi again

from the host it will be: “localhost:8545”

Well guess I’m just stupid :smiley:

I was using docker-machine the whole time instead of docker.app, apparently that’s not the recommended way to use docker on mac any more. Purged everything reinstalled docker.app, works without issues now ^^

Thanks for your help though!

oh! yea its more native now :slight_smile: