During a recent project where I was setting up a Docker swarm (which I will be covering in a future post) I ran into an issue when when trying to connect to the internet. All of our servers use a corporate web proxy and do not have direct access outbound to the internet for security reasons. Not an issue for the average enduser as the proxy settings are applied to the machine via GPO or enforced by the proxy client app - Zscaler in our case - and most, if not all, Windows applications play nicely. Not always the case for our servers however, even if we do specify the proxy settings via GPO, as some applications don't use the Windows IE proxy settings stored in the registry and instead rely on environment variables as is the case with Docker.
To overcome this issue, and allow Docker reach the internet and download container images etc, it was necessary to set the environment variables for HTTP_PROXY and HTTPS_PROXY on the server itself. These are system level settings so apply regardless of who is logged in and persist between reboots.
There are two ways to set these environment variables, either in the system settings UI or via a PowerShell command.
Option 1 - GUI
Click Start and search for "variables" and select the search result as shown below
Open an elevated PowerShell window and run the following lines to add your proxy settings to the environment variables
[Environment]::SetEnvironmentVariable("HTTP_PROXY", "http://username:password@proxy:port/", [EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable("HTTPS_PROXY", "http://username:password@proxy:port/", [EnvironmentVariableTarget]::Machine)
If you proxy server does not require authentication simply remove the "username:password@" section from the URL.
Restart Docker service
In order to apply the new settings to Docker you will need to restart the service. From an elevated PowerShell window run the following commad:
Restart-Service docker
Check Settings
Run docker info and check the proxy settings are showing in your configuration. You can also test a download by running docker pull hello-world and check the container image downloads correctly.