Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set 'host' as default network for Docker

Tags:

docker

Docker can build containers just fine up until I connect my Cisco VPN. After that, containers are unable to connect to the outside internet. It's more than a DNS problem, it simply can't route to anything outside of Docker's own network. Now, I can get around this by running containers with --net=host But the problem is with building containers with dockerfiles. I see no way to set the host there. Is there somewhere else I can configure docker to simply always use 'host' as the default network?

like image 245
directedition Avatar asked Apr 28 '17 13:04

directedition


People also ask

Which network is default network in Docker?

bridge : The default network driver. If you don't specify a driver, this is the type of network you are creating. Bridge networks are usually used when your applications run in standalone containers that need to communicate.

Does Docker use host network?

If you specify the --net=host option to the docker create or docker run commands, Docker uses the host's network stack for the container. The network configuration of the container is the same as that of the host and the container shares the service ports that are available to the host.


2 Answers

The docker build command also has a --network parameter that you can use to specify the network mode that should be used for intermediate containers. This flag has the same effect and possible values as the identically named parameter of the docker run command.

--network (=default) Set the networking mode for the RUN instructions during build

This should allow you to build your containers with:

docker build -t yourimagename --network=host .
like image 105
helmbert Avatar answered Sep 20 '22 09:09

helmbert


Dockerfile is to define how to build an image. It has no runtime parameters beyond setting the default command and/or entrypoint.

Networking is a runtime concern only. If using arguments to docker run is not fitting, perhaps you can use docker-compose.yml and either the docker-compose tool, or a swarm. In both cases, you can define network parameters for the container(s) defined in docker-compose.yml.

network_mode: "host"

See the documentation.

like image 26
Dan Lowe Avatar answered Sep 21 '22 09:09

Dan Lowe