How to use host network while linking to a container?

Since you expose postgis ports to host, you can skip linking and connect to it through localhost:9000. I believe this will work since the Laravel application resides on the host network and they will share those ports.


The reason why we use links keyword is so that docker can internally make hostname resolution so that two disparate containers can communicate with each other. In your case if you were not using host network and using the link keyword then docker would have created a hostname with each container names internally so both containers can communicate with each others. When you are using "host" mode network means you are telling docker that i shall be using the "hosts" underlying network and hence by simply exposing the ports on the localhost my containers can communicate with each other.