How to use host network while linking to a container?

In my docker-compose:

    image: trackware
        - postgis:postgis
        - "80:80"
        - "3306:3306"
        - "443:443"
        - "220:22"
        - "8000:8000"
    net: "host"
    restart:  always
        - C:/H/repositories/pubnub:/share
    container_name: laravel

    image: mdillon/postgis
    env_file: .postgis_env
        - "9090:9000"
        - "54320:5432"
    container_name: postgis

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

  • docker custom network connexion refused between
  • How to connect local kafka in docker container?
  • Store and Restore Inherited Dockerfile USER setting
  • docker-machine: Can't access container's web server from host
  • Kubernetes Jenkins plugin - slaves always offline
  • Ansible and docker: locally build image get pulled and causes failure
  • 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

  • Problems with docker container to container communication on same host when firewalld/iptables is enabled
  • reconfigure timezone inside docker not working
  • [Docker]: Connecting PHPMyAdmin to MySQL doesnt work
  • Failed to connect to port 8888: Timed out
  • Unable to correct problems, you have held broken packages
  • Plex using Ansible and Docker
  • 2 Solutions collect form web for “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 trough localhost:9000. I believe this will work since laravel application resides in host network and they will share those ports.

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.