Windows Docker Host Mode / Binding To Identical Ports/local IP

I’m on Windows 10, and have enabled “Enable host networking” in Features in development. I’m running docker v4.29.0, and have WSL v 2.0.1.0. I unfortunately am having problems upgrading WSL any further. This isn’t about WSL, though.

I’m using docker-compose to start up a containerized service I developed (A) that needs to, sometimes, initiate communication with another service I’m debugging on my local machine (B). Therefore, Service A needs to reach out to Service B, and I (maybe mistakenly) assume I have to have Service A in host mode so it can talk to Service B. I have successfully configured it to do so, and everything works great.

I found, however, that when I open my development environment for Service A and run it in debug mode, and it’s configured to bind to the same exact IP address (whether it’s 0.0.0.0 or 127.0.0.1) and port as the one hosted in docker/docker-compose, it does not throw an error indicating the port is in use. Both applications seem to be running, but all network traffic is routed to Service A in docker, rather than my debugging development environment.

I’m using .net 8.0 on the latest build, too, which makes me think this is a docker issue. Can anyone confirm this behavior with another language or explain why this is acting this way? I only care because with 10 or so services, going back and forth between debug mode is easy when it’s clear whether you’ve got the service running in docker and you have to shut it down to debug (i.e. your program crashes because it can’t bind to the port you want). Also, this seems like it shouldn’t be the desired behavior anywhere.

Here’s my (redacted) docker-compose.yaml:

name: placeholder-image
services:
  placeholder-image:
    network_mode: host
    container_name: placeholder-image
    image: placeholder.azurecr.io/placeholder-image:latest
    environment:
      Kestrel__Endpoints__Http__Url: http://127.0.0.1:9000
    volumes:
      - ./storage:/etc/storage