Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 684
charmosz Avatar asked Jul 29 '16 16:07

charmosz


People also ask

What is Network_mode host in Docker compose?

Docker network host, also known as Docker host networking, is a networking mode in which a Docker container shares its network namespace with the host machine. The application inside the container can be accessed using a port at the host's IP address (e.g., port 80).

How do I connect to host Docker internally?

To access host machine from the docker container you must attach an IP alias to your network interface. You can bind whichever IP you want, just make sure you're not using it to anything else. Then make sure that you server is listening to the IP mentioned above or 0.0. 0.0 .

Is Docker compose deprecated?

The Docker Compose V2 branch is now the default on GitHub. You can still find Docker Compose V1 in the `master` branch. Compose V1 is marked as deprecated, and we'll begin patching only high-severity vulnerabilities or fixing critical bugs until the next milestone.

Can Docker reach localhost?

Docker provides a host network which lets containers share your host's networking stack. This approach means localhost inside a container resolves to the physical host, instead of the container itself. Now your container can reference localhost or 127.0. 0.1 directly.


1 Answers

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".

like image 148
nice_pink Avatar answered Sep 18 '22 23:09

nice_pink