How to Configure a Proxy for #Docker on Windows (#WindowsContainer)Published on 12 Feb 2017
Tags #Docker #Container
When using Windows containers on Windows 10, you sometimes end up behind a proxy server. Unfortunately, the Docker service does not use the proxy server configured for Windows itself. Instead, it uses the environment variables commonly used on Linux.
Many Linux based tools can be configured to use a proxy server by providing the following environment variables:
HTTP_PROXYcontains the proxy server for HTTP connections, e.g.
HTTPS_PROXYcontains the proxy server for HTTPS connections
NO_PROXYdefines IP ranges excluded from the proxy, e.g.
10.0.0.0/8 192.168.0.0/16 172.16.0.0/12
Although you can create a start script for the Docker service, I recommend not to do this. Firstly, because it limits the proxy configuration to a single service. Secondly, it is harder to change the proxy configuration.
Instead, I recommend, you define the environment variables for the whole system. If using other tools relying on those environment variables, all are automatically configured to use the proxy server.
System variables can either be configured using the builtin dialog:
If you are switching between proxy servers regularly, using the following code make this process a lot easier:
[Environment]::SetEnvironmentVariable("HTTP_PROXY", "http://220.127.116.11:3128", [EnvironmentVariableTarget]::Machine) [Environment]::SetEnvironmentVariable("HTTPS_PROXY", "http://18.104.22.168:3128", [EnvironmentVariableTarget]::Machine) Restart-Service -Name docker