Pass --net=host to docker build

2020-05-31 05:35发布

问题:

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!

回答1:

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



回答2:

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



回答3:

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!



标签: docker