27

To pass other options to docker build, you can speciy DOCKER_OPTS in /etc/default/docker, however --net is not available. Is it possible to use the host's networking stack when building a container?

I'm running Docker version 1.3.2, build 39fa2fa.

Thanks!

user2334289
  • 273
  • 1
  • 3
  • 5
  • Why do you want to do this? – Bryan Dec 12 '14 at 10:16
  • 2
    I'd like to use my hosts networking stack when building containers. I have trouble getting a docker container to use my company's intranet's dns server at build time. Using --net=host was the easiest way to get it working when running a container. – user2334289 Dec 12 '14 at 19:27

3 Answers3

33

Try --network instead of --net. It is new in the 1.25 API and sets the networking mode for the RUN instructions.

gukoff
  • 2,112
  • 3
  • 18
  • 30
  • I tried Sergey's answer .. that and only that didn't work ... then I tried this on top of it ... worked ! – dparkar Jul 18 '18 at 22:52
15

To solve the problem, configure docker daemon to use the your company DNS server. For instance, if your resolv.conf has the following configuration:

$> cat /etc/resolv.conf
domain mycompany
search mycompany
nameserver 10.123.123.123

Change /etc/default/docker to contain the following:

DOCKER_OPTS="--dns 10.123.123.123"

And restart docker daemon with:

sudo service docker restart

Now, containers will have access to the intranet during the build operation.

Related answer: Dockerfile: Docker build can't download packages: centos->yum, debian/ubuntu->apt-get behind intranet

Community
  • 1
  • 1
Sergey Evstifeev
  • 4,941
  • 2
  • 24
  • 28
  • 1
    I also had to remove private DNS as in (http://askubuntu.com/questions/627899/nameserver-127-0-1-1-in-resolv-conf-wont-go-away) BONUS oneliner: DOCKER_OPTS=$(cat /etc/resolv.conf | grep nameserver | awk '{ printf " --dns " $2 }') && sudo service docker restart – ElMesa May 02 '16 at 12:11
  • And to find your DNS ip in windows use ipconfig /all | findstr /R "DNS\ Servers" originally https://superuser.com/a/486925 –  Dec 15 '17 at 14:28
10

From the newest versions (currently docker ce v17) it is possible to add --network=host to your docker build command which is similar to --net=host when using docker run!

Nicholas
  • 1,189
  • 4
  • 20
  • 40