Configure Docker to Use a Proxy Server

Guardian By Guardian 4 Min Read

In today’s interconnected world, efficient communication between software components is critical. However, when working behind a corporate firewall or within an organization’s network, you may encounter proxy servers that control Internet access. In this step-by-step guide, we will explore how to configure the Docker client to use proxy settings, ensuring a smooth development workflow even in restricted environments.

Configure Docker Using Environment Variables

You can add proxy configuration for the Docker client using a JSON configuration file located at ~/.docker/config.json. This configuration affects builds and containers that use the specified proxy settings.

Create or Edit the config.json File:

  • The file is typically located at ~/.docker/config.json.
  • Add the following proxy settings (customize them according to your environment):
{
    "proxies": {
        "default": {
            "httpProxy": "http://username:password@localhost:3128",
            "httpsProxy": "http://username:password@localhost:3129",
            "noProxy": "*.test.example.com,.example.org,127.0.0.0/8"
        }
    }
}
  • Replace usernamepasswordlocalhost, and the port numbers with your actual proxy details and save the file.
  • Note that the format is http://username:password@proxy:port
  • The configuration is activated immediately, you do not need to restart Docker.
  • Note that proxy settings may contain sensitive information, so be careful when storing them in the configuration file.

Verify the Configuration:

  • Run Docker commands (e.g., docker pulldocker build) to ensure they use the specified proxy settings.

Available Configuration Parameters

The following table describes the configuration parameters available in config.json:

PropertyDescription
httpProxySets the HTTP_PROXY and http_proxy environment variables and build arguments.
httpsProxy Sets the HTTPS_PROXY and https_proxy environment variables and build arguments.
ftpProxySets the FTP_PROXY and ftp_proxy environment variables and build arguments.
noProxySets the NO_PROXY and no_proxy environment variables and build arguments.
allProxySets the ALL_PROXY and all_proxy environment variables and build arguments.
configuration parameters in config.json

These settings only configure proxy environment variables for containers and do not affect the Docker CLI or Docker Engine.

FAQ’s

Q1: Why do I need to configure proxy settings for Docker?

Proxy settings are essential when working behind a corporate firewall or within a restricted network. They allow Docker to communicate with external registries, pull images, and access repositories seamlessly.

Q2: How can I set up a proxy server for Docker?

Follow our step-by-step guide in the article to configure the Docker client using environment variables or a config.json file. Additionally, consider using popular proxy server software like Squid for enhanced control and security.

Q3: Can I use different proxies for HTTP and HTTPS requests?

Yes, you can specify separate proxy settings for HTTP (httpProxy) and HTTPS (httpsProxy) requests. Customize these settings based on your network requirements.

Q4: What if my proxy requires authentication?

If your proxy server requires authentication (username and password), include them in the proxy URL. For example: http://username:password@localhost:3128.

Q5: How do I verify that my Docker client is using the proxy?

Run Docker commands (e.g., docker pulldocker build) and monitor the logs to ensure they reflect the specified proxy settings.

Q6: Is Squid the only proxy server option for Docker?

No, squid is just an option. You can explore other proxy server software like Nginx or Apache depending on your needs.

Conclusion

By following this guide, you have successfully configured the Docker client to use proxy settings. Now you can work with Docker images and containers even in restricted network environments. Happy Dockerizing!

Share This Article