0

I have a docker-compose file with two services

  • React frontend, connects to backend via a localhost address (easy enough)
  • ASP.NET CORE backend that connects to a local mongo instance via the docker network bridge

I need this to be able to restart and work every time my Windows PC restarts. The trouble is the gateway address for the docker bridge gateway changes every time my PC restarts. I get the same result every time if I run "docker network inspect bridge", but the address to bind to mongo seems to be a random address from that subnet (vEthernet when running ipconfig). I hope this makes sense, essentially I just need my backend to be able to connect to a local mongo instance without needing additional configuration each time. Is there a way I can configure this in my compose file? This is my current file

version: "3.9"
services:
  taxifrontend:
    image: tstaxibooker:1.3.3
    ports:
      - "4012:80"
    restart: always
  taxibackend:
    image: taxibookerbackend:1.1
    network_mode: bridge
    ports:
      - "8000:80"
    restart: always
    extra_hosts:
      - "mongoservice:172.18.240.1"

The address I need to bind to mongoservice seems to constantly change.

Daniel M
  • 133
  • 3
  • 9
  • Where is the database running? On a dedicated host? In a separate container that's not part of this Compose setup? Outside a container but on the same host? – David Maze May 20 '22 at 15:58
  • The database is running on my local windows machine, I have docker desktop installed where I'll be running the two containers – Daniel M May 20 '22 at 16:04
  • Does removing `extra_hosts` and using the magic host name `host.docker.internal` work? Also see [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – David Maze May 20 '22 at 17:13
  • This worked like a treat thank you. only downside is having to change connection strings when doing dev, but I can probably split them out into environment vars – Daniel M May 21 '22 at 14:32

0 Answers0