I have a Docker environment (technically, Laravel Sail) and I am trying to access a web app (running on port 9000) on the host machine (running Ubuntu Linux). Docker and Ubuntu are up-to-date. I have set up the simplest example to demonstrate the issue. My docker compose defines a new network (sail) using the bridge driver. On the host machine, I am running a simple webserver (localhost:9000) available from PHP:
$ php -S localhost:9000A local port scan on my host machine shows that this port is open and I can communicate with it.
$ nmap 127.0.0.1PORT STATE SERVICE80/tcp open http443/tcp open https . . .8000/tcp open http-alt8081/tcp open blackice-icecap9000/tcp open cslistenerNow, if I open up a shell inside my Docker container and run a port scan on the host machine, I get a different output:
$ nmap host.docker.internalPORT STATE SERVICE80/tcp open http443/tcp open https...8000/tcp open http-altIn the first (local) port scan, I included a few other services to show that ports are open but not available in the Docker container.
I ensured my firewall is stopped on my local machine:
$ sudo ufw disable && sudo ufw statusFirewall stopped and disabled on system startupStatus: inactiveI ran the same exact Docker environment on macOS and it works fine.
I can ping my host and the IP address shows in the expected range:
$ ping -c 1 host.docker.internalPING host.docker.internal (172.17.0.1) 56(84) bytes of data.64 bytes from host.docker.internal (172.17.0.1): icmp_seq=1 ttl=64 time=0.067 msInside the container, the host machine has one IP address inside the docker-host-machine-range:
$ ip route show defaultdefault via 172.19.0.1 dev eth0 However, when I check the IP address of the Docker virtual bridge:
$ ip addr show docker0 ... ... inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 ...So, there is a IP range mismatch. I'm not sure if that is worth further investigation.
I've rebooted the host machine and rebuilt the Docker container.
How would I connect from my container to a web app on my Linux-based host machine?