0

I have services defined in my own docker-compose.yaml file, and they have their own bridged network to communicate with each other.

One of this services needs access to services running on the host machine.

According to this answer I added the following lines to my service within the docker-compose.yaml file:

extra_hosts:
  - "host.docker.internal:host-gateway"

This works, despite the fact that the services running on the host need to bind to 0.0.0.0. If I bind to localhost, I'm not able to access them. But I don't want to expose the port to anyone else.

Is there a way to achieve this with bridged network mode?

I'm using the following versions:

  • Docker version 20.10.5, build 55c4c88
  • docker-compose version 1.28.5, build unknown

and I'm running on aarch64

Frant
  • 3,769
  • 1
  • 11
  • 20
divadpoc
  • 722
  • 8
  • 27

1 Answers1

0

the solution was just a misunderstanding from other readings. e.g.

As I explicitly defined an additional bridged network within my docker-compose.yaml file I assumed that I had to bind the service on the host to the IP address of that particular interface (I checked the IP address of the container and then looked up the address on the host's interface list) which was 172.20.0.1)

But docker0 was 172.17.0.1 (which should be the default one).

After binding the service on the host to the docker0 IP address, and adding

extra_hosts:
  - "host.docker.internal:host-gateway"

to `docker-compose.yaml', I was able to access it, but it was also blocked from anyone else.

The explanation why this is working is probably, as explained here, b/c the IP route within each docker container includes the docker0 IP address, even if you have your own network set up.

Please correct me in case I mixed something up.

divadpoc
  • 722
  • 8
  • 27