Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use host network while linking to a container?

In my docker-compose:

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 would I use net: "host" while linking to postgis container? laravel container needs to run pubnub client, which will need high-performance networking for real time messages handling, and also it needs to link to postgis container to access db.

So, any advice? I am using docker 1.10.2

like image 623
simo Avatar asked Feb 26 '16 11:02

simo


People also ask

Can Docker containers Access host network?

Your host can still be accessed from containers in the default bridge networking mode. You just need to reference it by its Docker network IP, instead of localhost or 127.0. 0.1 . Your host's Docker IP will be shown on the inet line.


2 Answers

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.

like image 113
h.s.o.b.s Avatar answered Oct 11 '22 19:10

h.s.o.b.s


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.

like image 38
Rohit Salecha Avatar answered Oct 11 '22 19:10

Rohit Salecha