Port on host.docker.internal still open but not on real host IP

Given I have a port open on the Docker host and I close this port (close the application) - connecting through host.docker.internal still sees the port as open.

Attached nmap against host.docker.internal vs the real local IP address of the host.

So whats going on?

root@0ecb807fed16:/var/www/html# nmap -p 10003 host.docker.internal
Starting Nmap 7.80 ( https://nmap.org ) at 2022-04-08 21:44 UTC
Nmap scan report for host.docker.internal (192.168.65.2)
Host is up (0.00035s latency).

PORT      STATE SERVICE
10003/tcp open  documentum_s

Nmap done: 1 IP address (1 host up) scanned in 0.20 seconds
root@0ecb807fed16:/var/www/html# nmap -p 10003 172.16.100.250
Starting Nmap 7.80 ( https://nmap.org ) at 2022-04-08 21:44 UTC
Nmap scan report for 172.16.100.250
Host is up (0.00058s latency).

PORT      STATE  SERVICE
10003/tcp closed documentum_s

Nmap done: 1 IP address (1 host up) scanned in 0.21 seconds

Thank you for your help!

I don’t exactly know how host.docker.internal works, but it points to the IP address of the virtual machine which is the real Docker host. It then must forward traffic to your Mac, which is probably considered an internal request and you can still access that port locally.

Thank you for your reply @rimelek!

I want that port to be unavailable (closed) when the application listening for it in the host is closed.

Pretty weird.