How to use a host network when connecting to a container?

In my docker essay:

laravel: image: trackware links: - postgis:postgis ports: - "80:80" - "3306:3306" - "443:443" - "220:22" - "8000:8000" net: "host" restart: always volumes: - C:/H/repositories/pubnub:/share container_name: laravel postgis: image: mdillon/postgis env_file: .postgis_env ports: - "9090:9000" - "54320:5432" container_name: postgis 

if I run docker-compose up -d , I get this error:

 Conflicting options: host type networking can't be used with links. This would result in undefined behavior 

So how to use net: "host" when linking to a postgis container? The laravel container must run the pubnub client, which requires a high-performance network to process messages in real time, and also to communicate with the postgis container to access db.

So any tips? I am using docker 1.10.2

+11
source share
2 answers

Since you open postgis ports for the host, you can skip the connection and connect to it through localhost:9000 . I believe this will work since the Laravel application is on the host network and they will use these ports.

+6
source

I do not know, but ... You should not use the host driver and port mapping, at least you will not get the expected result. In the case of, for example, "220: 22", you will receive 22 ports mapped to the host machine.

"Net" is deprecated as far as I know, use " network_mode " instead. I would also recommend that you upgrade docker-compose to the latest version, now it's 1.6.2. Previous versions had some network issues.

Maybe you can use the " bridge " driver? In your case, I do not see problems that he cannot solve.

0
source

Source: https://habr.com/ru/post/1243935/


All Articles