Is it possible to specify network for "docker build" command?

My build command requires container image to connect to internet to download some files. It fails during that connection. I want to specify bridged network instead of NAT one to prevent possibility that NAT connectivity causing the issue. I don’t see option to specify network in “docker build” command. Spawned containers have properly access to external network once they spawn.
Error is below

Unable to download from URI
'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
VERBOSE: [4EE37530AFA6]:

Can you post your Dockerfile?

This is not being done inside docker file but inside one of the scripts. Docker file is below.

FROM microsoft/iis
ADD server_config.ps1 ./serverconfig.ps1
ADD iis.ps1 ./iisconfig.ps1
ADD startup.ps1 ./startup.ps1
RUN powershell.exe .\serverconfig.ps1; .\iisconfig.ps1
CMD powershell.exe .\startup.ps1;C:\ServiceMonitor.exe w3svc
EXPOSE 80

It’s a lot easier to debug if you don’t jam it into scripts. If that doesn’t work, can you post the content of the script that downloads this?

I’m not sure that’s the problem, but with 1.13 docker build does have a network option: https://github.com/docker/docker/releases/tag/v1.13.0-rc4

So you can upgrade to that if that’s not what you have already.

Not sure if you are running into this locally (dev machine) or on a remote build server. Corporate networks are a living hell.

Locally I rely on CNTLM on my dev machine to resolve both network and proxy issues. This means using “–build-arg” on docker build commands (the “http_proxy” and “https_proxy” are always valid arguments).

Your dev machine IP (from the container point of view) will vary depending on your environment.

I resolved the issue by configuring alternative “bridge” network during build command. It works fine (as expected). NATted networks on client machine was blocked by firewall on client since request seems to be coming from 172.x network and firewall was considering this requests “bad”. Can not control firewall settings in corporate network, they don’t have any issues with bridge network though.

1 Like

@artisticcheese: I am facing exactly same issue.
I am a novice in using dockers. Can you please share the instructions for configuring the bridge network.

If you have issues with firewall blocking traffic then fix firewall. Creating bridge network is not a solution since this is not you are going to use for production deployment.

@artisticcheese It is a network firewall and nothing can be done about that. Plus the network requires me to login to connect to the internet.
I need a workaround by making the docker use my local machines internet connection, both while building and when running a container.

Well I don’t remember details but it’s really 2 commands

  1. You create network of type bridge (check help for docker network)
  2. Specify at run time that your container need to use that network via --network setting