Proxy 101 for DevOps: What They Are and How to Configure Them in Docker

Muskan AgrawalMuskan Agrawal
3 min read

Life used to be simple when proxy meant pleading your friend to answer your roll call and then taking them out to the nearest food truck to say thank you.

Fast forward to a few years later…

You’re now in the IT world and proxies hold a different meaning altogether which brings us to the question:

What is a proxy?

Continuing the analogy, proxy in the IT world is still your friend. It is the intermediary that gets your(client) request to the professor (server). Instead of connecting directly to the destination server, the client sends its request to the proxy, which then forwards the request on behalf of the client, receives the response, and passes it back to the client.

Why do containers use proxy?

Containers use proxies to safely access external resources, comply with security policies, load balance traffic, enable service discovery, and support advanced architectures like service mesh. Proxies are essential for both outbound and ingress inbound traffic management in modern DevOps environments. Whether you’re running Docker, Kubernetes, or a service mesh, understanding and configuring proxies is a foundational skill for effective container networking.

How to set proxy?

To configure a proxy in a Docker container, you can use environment variables or the Docker configuration file. Here are the most common and reliable methods:

1. Set Proxy When Running a Container

You can inject proxy configuration as environment variables using the --env flag:

docker run -e HTTP_PROXY="http://proxy.example.com:3128" \
           -e HTTPS_PROXY="http://proxy.example.com:3129" \
           -e NO_PROXY="localhost,127.0.0.1,.mydomain.com" \
           myimage
  • HTTP_PROXY and HTTPS_PROXY point to your proxy server.

  • NO_PROXY lists addresses that should bypass the proxy.

2. Set Proxy for All Containers (Global Default)

To apply proxy settings to all your containers automatically:

  • Edit or create ~/.docker/config.json on your machine:
{
  "proxies": {
    "default": {
      "httpProxy": "http://proxy.example.com:3128",
      "httpsProxy": "https://proxy.example.com:3129",
      "noProxy": "*.internal.domain,.example.com,127.0.0.1"
    }
  }
}
  • All new containers will inherit these proxy environment variables.

3. Setting Proxies in a Dockerfile (Build Time)

If you want your proxy settings included when building Docker images:

  • Pass build arguments during docker build:
docker build --build-arg HTTP_PROXY="http://proxy.example.com:3128" .
  • Or, set them directly in your Dockerfile:
ENV HTTP_PROXY="http://proxy.example.com:3128"
ENV HTTPS_PROXY="http://proxy.example.com:3129"

4. Verify Proxy Settings in the Container

You can check if your settings took effect by running:

docker run --rm alpine sh -c 'env | grep -i proxy'

This should list the *_PROXY variables and their values.

Tips

  • Always remember to set both upper and lowercase environment variables (e.g., http_proxy and HTTP_PROXY), as some applications are case-sensitive.

  • For sensitive credentials in proxy URLs, prefer not to store them in files that may be shared or committed to version control.

  • If you need to exclude some hosts or subnets from being proxied, use the NO_PROXY variable with a comma-separated list.

0
Subscribe to my newsletter

Read articles from Muskan Agrawal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Muskan Agrawal
Muskan Agrawal

Cloud and DevOps professional with a passion for automation, containers, and cloud-native practices—committed to sharing lessons from the trenches while always seeking new challenges. Combining hands-on expertise with an open mind, I write to demystify the complexities of DevOps and grow alongside the tech community.