How to use host network while linking to a container? How to use host network while linking to a container? docker docker

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.


I dunno reason but... You shouldn't use "host" driver and port mapping, at least you wouldn't get expected result. In case like this "220:22" you'll get 22 port mapped to the host machine.

"Net" is outdated as far as I know, use "network_mode" instead. Also I would recommend you to update docker-compose to the latest version, now is 1.6.2. Previous versions had some networking problems.

May be you can use "bridge" driver? In your case, I can't see problems which it couldn't resolve.