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?
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).
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 .
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.
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.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With