This tutorial quickly shows you how to configure the Docker if you are behind an HTTP proxy such as Nginx or HAProxy.
Configure the Docker Client to Use Proxy
The first and most common method that you can use to configure Docker to use a proxy is adding the configuration of the Docker client in the ~/.docker/config.json.
Edit the file and add the configuration as follows:
"proxies": {
"default": {
"httpProxy": "http://proxy.example.com:3128",
"httpsProxy": "https://proxy.example.com:3129",
"noProxy": "*.test.example.com,.example.org,127.0.0.0/8"
}
}
}
Replace the given configuration with the details of your Proxy servers.
Save and close the file. This forces the Docker client to reload the changes that are defined in the file and apply the configuration. Keep in mind that the changes apply to new containers. This does not affect the existing containers.
Configure the Proxy Settings Per Daemon
You can also configure the proxy usage in Docker in the daemon configuration file. Edit the “/etc/docker/daemon.json” file and add the properties of the proxies as follows:
"proxies": {
"default": {
"httpProxy": "http://proxy.example.com:3128",
"httpsProxy": "https://proxy.example.com:3129",
"noProxy": "*.test.example.com,.example.org,127.0.0.0/8"
},
"tcp://docker-daemon1.example.com": {
"noProxy": "*.internal.example.net"
}
}
}
Similarly, ensure to configure the details for your Proxy server in the provided parameters.
Configure Proxy Using the CLI
You can also set the proxy configuration in the command-line instead of using the Docker daemon. To set the proxy within the command-line, use the –env flags as shown in the following command:
You can also use the –build-env parameter instead as follows:
Conclusion
In this tutorial, we learned how to quickly configure the proxy settings for the Docker Engine using the daemon configuration file or the CLI.