charmosz
charmosz

Reputation: 133

docker-compose network_mode: "host" doesn't seem to work

I try to build containers with a docker-compose.yml file :

version: '2'

services:
     geonode:
        build: 
            context: .
        hostname: geonode
        container_name: geonode
        ports:
            - 8000:8000
        volumes:
            - .:/geonode/
        entrypoint:
            - /usr/bin/python
        command: manage.py runserver 0.0.0.0:8000
        network_mode: host

In my Dockerfile I run apt-get update after FROM ubuntu:14.04 but it fails : Could not resolve 'archive.ubuntu.com'

I tried docker run -i -t --net=host ubuntu:14.04 /bin/bash and then run apt-get update and it works. So it seems to me that the network_mode in docker-compose and the --net=host with docker run don't work the same way.

Does somebody has an explanation?

Upvotes: 9

Views: 17880

Answers (2)

BMitch
BMitch

Reputation: 263666

Since this answer was posted, docker build --network is now an option. So you can run:

docker build --network host -t charmosz/geonode .

And as of the compose file 2.2, this is an option in compose:

version: '2.2'

services:
  geonode:
    image: charmosz/geonode
    build:
      context: .
      network: host
    ...

You may be seeing a network collision with the bridge network. In that case, setting the "bip" can change the subnet used by docker for the default bridge network named bridge by setting the following in the daemon.json file:

{ "bip": "172.16.100.1/24" }

You'll need to restart docker for that change to apply. I've presented on this recently (note the previous slides show where to configure daemon.json options in Mac and Windows).

Upvotes: 2

nice_pink
nice_pink

Reputation: 523

It works at least in version 3.7 when doing:

services:
    my-app:
        container_name: my-app
        build: 
            context: .
            network: host
        network_mode: host
        command: /app/my-app

The ports are obsolete as all ports are "exposed".

Upvotes: 3

Related Questions