0

I have two distinct docker containers, independent from each other.

Now I want to talk from one to the other. Is that only possible by IP:PORT? Or even by application name?

This is the container I want to talk to:

docker-compose.yml:

services:
  my-container:
    ...
    ports:
      - "8090:8080"
    extra_hosts:
        - "host.docker.internal:host-gateway"

Is there a way that another container could simply connect to http://my-container? Or would I always have to go the way injecting the host network ip with extra_hosts to both containers, and then connect with http://host.docker.internal?

Sidenote: all my containers are on the same default docker bridge network.

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • they need to be in the same network – Def Soudani May 18 '22 at 12:55
  • ...and that network needs to _not_ be the "default bridge network". If you're running in Compose, it automatically creates a "user-defined bridge network" named `default`. – David Maze May 18 '22 at 12:59
  • Okay, and how could I merge both "user-defined bridge networks" named default? Or are they already both in the same "default" bridge network if I didn't set any? – membersound May 18 '22 at 13:03
  • I've linked this question to two others that answer the question. The "communicate via hostname" question discusses manually setting up the Docker network; "communication between projects" talks about configuring two Compose files to talk to each other. – David Maze May 18 '22 at 13:06
  • (The `default` network is scoped to a specific Compose project, but you can configure one project's `default` network to actually be the other's.) – David Maze May 18 '22 at 13:06

0 Answers0