How to Configure a Proxy for #Docker on Windows (#WindowsContainer)

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:

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:

Dialog for system variables

If you are switching between proxy servers regularly, using the following code make this process a lot easier:

[Environment]::SetEnvironmentVariable("HTTP_PROXY", "http://1.2.3.4:3128", [EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable("HTTPS_PROXY", "http://1.2.3.4:3128", [EnvironmentVariableTarget]::Machine)
Restart-Service -Name docker
Feedback is always welcome! If you'd like to get in touch with me concerning the contents of this article, please use Twitter.