Is "docker build --network=host" working as expected?

is “docker build --network=host” working as expected?

I tried building image with --network flag expecting that while running, docker container will pickup host network by default instead of bridge network. However, it did not happen. Upon docker inspect, I found out that container still has bridge network.

I want to avoid giving “–network=host” to docker run command.

docker build help says –

–network default Set the networking mode for the RUN instructions during build

Any pointers if I am missing anything?

The network specified in build is different from network specified in run. The network specified in build is only for downloading packages that are necessary for building image. The network specified in run is for the containers itself.

I have been fighting this for a day now. Thanks for the clarification.

I am trying to develop an automated install of many perl CPAN modules that need networking activated to pass tests at installation. Whenever I used the Dockerfile to run cpanm it fails however when I connect into a container and run the commands manually it always worked…

Is it possible to have a build network that is the same as the container?

Otherwise I could build the environment I need in the container manually and then make an image out of that. Not my favourite approach but will work it work?

You can specify the network used for build as well as container. These are 2 independent things and you can use the same network for both. I am not clear why build would fail without container. Is it failing because its not able to connect to outside world?
It is fine to make builds inside a container as well.

I just use all default settings. The docker build is based on a centos7 image. If I start a container of that image and then run the installation commands everything works.
If I place those commands into a Docker file, the installation fails to make the network connection tests.
I would like to know what the difference between the two network environments are. How can I check that?
How can I ensure that the build networking setup is the same as the container networking setup?

I found out how to save a container as a new image. However I would prefer a fully automated solution.

Thanks for your guidance.

Can you pls put your Dockerfile and the error you are getting. I am assuming that you are not behind any proxy.

I am not behind a proxy at this point. I am trying a different approach using the debian-based perl build in the repository. If that works then it must be something in CentOS7. So far the debian base is working… I will explore the buildpack-deps:stretch to ensure I get an equivalent CentOS7 base.

The build errors are not helpful except that they are all network checks that fail.

The Docker file is essentially:

ENV PINTO_REPOSITORY_ROOT /var/lib/pinto
ENV PINTO_USERNAME pinto
ENV USERNAME pinto
RUN cpanm Task::Kensho

which is an attempt to load a large number of perl modules from CPAN using the cpanm command.

I have to use CentOS7 because when I get to work, that is what I need to execute on.

for that problem I had to reconfigure docker-deamon
so in /etc/default/docker try this
: OCKER_OPTS="–dns 8.8.8.8"
then restart the docker service