Running Docker containers behind an authenticated HTTP proxy

Updated:

A Docker proxy setup starts with one question: which traffic should leave through the proxy? Docker has three separate paths (your app at runtime, docker build, and the daemon pulling images), and each reads its proxy from a different place. Get that right and every container on one host can exit through its own ProxyV4 IPv4 address while the host's routing table stays untouched.

Docker · HTTP Proxy Format
ENV HTTP_PROXY=http://user:pass@ip:port HTTPS_PROXY=http://user:pass@ip:port

Three places Docker reads a proxy from

Setting a variable in one scope does nothing for the other two. A common surprise is a working docker pull while the app inside the container still goes out on the host's own IP, or the reverse.

TrafficConfigure it inTypical content
Your application inside a running containerdocker run -e HTTP_PROXY=... or the environment: block in ComposeScraper requests, API calls, automation jobs
Commands during docker build--build-arg HTTP_PROXY=http://user:pass@ip:portapt, pip and npm downloads in RUN steps
The Docker daemon itself/etc/systemd/system/docker.service.d/http-proxy.confdocker pull and docker push against registries

One IP per container

Because the runtime variables live in each container's environment, a single VPS can run, say, ten workers where each one has a different http://user:pass@ip:port value. Every worker then shows its own exit address to the sites it visits, and since a ProxyV4 private IPv4 is rented to one customer only, nobody else's traffic shares that address.

Keep one .env file per service, or one Compose service per proxy, so you can see at a glance which IP belongs to which job. When you renew, you can keep the same addresses, so nothing in those files has to change.

Variables that keep the stack working

  • Define the uppercase names (HTTP_PROXY, HTTPS_PROXY, NO_PROXY) and the lowercase ones (http_proxy, https_proxy, no_proxy); different tools and runtimes look for different spellings
  • Put every Compose service name your app calls in NO_PROXY, for example NO_PROXY=localhost,127.0.0.1,redis,postgres, so database and cache traffic stays on the bridge network instead of being sent to the proxy
  • Use the http:// scheme for HTTPS_PROXY too; the client opens a CONNECT tunnel and HTTPS sites stay encrypted
  • Do not write proxy passwords into a Dockerfile with ENV: they end up in the image layers. Inject them at runtime from .env or the Compose file

Step by step

  1. 1

    Turn the order line into a proxy URL

    Your ProxyV4 order lists ip:port:user:pass; rewrite it as http://user:pass@ip:port, by hand or with the proxy format converter.

  2. 2

    Add the variables to the service

    In docker-compose.yml, under the service's environment:, set HTTP_PROXY, HTTPS_PROXY, http_proxy, https_proxy and NO_PROXY=localhost,127.0.0.1,redis,db.

  3. 3

    Recreate the container

    Environment changes apply only to new containers, so run docker compose up -d to recreate the service.

  4. 4

    Check the exit IP from inside

    Run docker exec -it <container> curl -s https://proxyv4.com/api/my-ip. The address returned should be the proxy IP, not the host's.

Frequently asked questions

After adding HTTP_PROXY my app cannot reach Redis or Postgres. Why?

The HTTP client is now sending requests for redis or db to the external proxy, which cannot resolve those internal names. List them in NO_PROXY (and no_proxy), e.g. NO_PROXY=localhost,127.0.0.1,redis,db, then recreate the container.

Can each container on one server use a different proxy?

Yes. Give each service, or each .env file, its own http://user:pass@ip:port value. The containers share the host but leave the internet on separate IPs.

Why set the proxy variables twice, in upper and lower case?

There is no single standard. Tools built on libcurl read lowercase http_proxy and https_proxy, while many Go and Node tools read the uppercase names. Setting both covers everything in the image.

Does `docker pull` use the variables I set in Compose?

No. Pulls are made by the daemon, which reads its proxy from the systemd drop-in /etc/systemd/system/docker.service.d/http-proxy.conf, not from container environments.

A separate private IPv4 for every container

Unmetered private IPv4 in 7 countries plus static ISP in the US and Vietnam, issued automatically after payment. No minimum order.

Check live Singapore prices

Related articles

Proxy setup
Configuring a Proxy on Ubuntu and Debian, Layer by Layer
Configure an HTTP(S) proxy on Ubuntu or Debian for every layer that needs it: shell variables, APT, systemd services, sudo and the GNOME desktop settings.
Proxy setup
Using cURL with an authenticated proxy: commands that prove it works
Send cURL requests through an authenticated HTTP(S) proxy with -x and -U, confirm the exit IP, read the CONNECT handshake and time each request on any OS.
Proxies by platform
Proxies for web scraping: a fixed pool of IPs with unmetered traffic
Web scraping proxies for Python, Scrapy, Playwright and Selenium: a pool of private IPv4 and static ISP addresses, unlimited bandwidth, flat per-IP pricing.
Proxies by platform
Airdrop and Grass proxies: a separate IPv4 for every wallet and node
Airdrop and Grass proxies that give each wallet and DePIN node its own IPv4. Static ISP for Grass, Dawn and Nodepay; private IPv4 for quests and testnets.
Proxies by platform
Proxies for SEO rank tracking: see the results page a local searcher sees
SEO rank tracking proxies with a private IPv4 in the US, UK, Vietnam, Japan and four more markets, so rankings, local packs and ads match what locals see.
IPV4 · singapore
One Fixed Singapore IP for Every Regional Store and Ad Account
Singapore private IPv4 proxy: a static SG datacenter IP used by you alone, for Lazada and Shopee SG stores, Singapore ad accounts and regional automation.
IPV4 · united states
Build a US IP Pool for Scraping, Rank Tracking and Ad Checks
Buy US private IPv4 proxies: static American datacenter IPs, one customer per IP, unlimited bandwidth. Built for scraping, SERP tracking and US ad checks.
Use cases
Designing a scraper around a pool of dedicated IPs
Web scraping proxies for data teams: size a pool of private static IPs, rotate them in your own code, choose IPv4, ISP or IPv6, and collect data responsibly.