How to set up a proxy in Docker (Containers, Compose & Builds)
Updated:
When running multi-container scrapers, automation workers, or DePIN nodes on a single host server, passing HTTP_PROXY and HTTPS_PROXY environment variables per container lets each service exit through its own dedicated static IPv4 address from VinaProxy without altering the host machine's routing table.
ENV HTTP_PROXY=http://user:pass@ip:port HTTPS_PROXY=http://user:pass@ip:port- 1 IP₫40,000
- 5+ IPs₫35,000
- 10+ IPs₫25,000
- 20+ IPs₫25,000
- 50+ IPs₫25,000
- 100+ IPs₫25,000
- 200+ IPs₫25,000
- 500+ IPs₫25,000
- 1000+ IPs₫22,000
- 2000+ IPs₫20,000
- 1 IP₫40,000
- 5+ IPs₫35,000
- 10+ IPs₫25,000
- 20+ IPs₫25,000
- 50+ IPs₫25,000
- 100+ IPs₫25,000
- 200+ IPs₫25,000
- 500+ IPs₫25,000
- 1000+ IPs₫22,000
- 2000+ IPs₫20,000
Understanding the 3 Docker proxy configuration scopes
Docker separates container runtime traffic, image build traffic, and daemon registry pulls:
| Docker Scope | Where to Configure | What It Routes |
|---|---|---|
| 1. Container Runtime | docker run -e HTTP_PROXY=... or Compose environment: | Traffic generated by the app inside that specific container |
2. Image Build (docker build) | --build-arg HTTP_PROXY=http://user:pass@ip:port | Package manager downloads (apt, pip, npm) during build |
3. Docker Daemon (dockerd) | /etc/systemd/system/docker.service.d/http-proxy.conf | docker pull and docker push requests to registries |
Docker Compose best practices & NO_PROXY rules
- Set both uppercase (
HTTP_PROXY,HTTPS_PROXY,NO_PROXY) and lowercase (http_proxy,https_proxy,no_proxy) variables so all Linux CLI tools and language runtimes pick them up - Always list internal Docker Compose service names (e.g.,
NO_PROXY=localhost,127.0.0.1,redis,postgres) so inter-container traffic stays on the local bridge network - Never bake proxy passwords into public images with
ENVinside aDockerfile—inject them at runtime via.envordocker-compose.yml
Step by step
- 1
Format your proxy as http://user:pass@ip:port
Convert your VinaProxy
ip:port:user:passline using our Proxy Format Converter. - 2
Add environment variables to docker-compose.yml
Under your service's
environment:, defineHTTP_PROXY,HTTPS_PROXY,http_proxy,https_proxy, andNO_PROXY=localhost,127.0.0.1,redis,db. - 3
Start or recreate the container
Run
docker compose up -dto apply the environment variables. - 4
Verify exit IP from inside the container
Execute
docker exec -it <container> curl -s https://vinaproxy.com/api/my-ipto confirm the container exits through your proxy IP.
Frequently asked questions
Why can't my container reach my Redis or Postgres container after setting HTTP_PROXY?
Without NO_PROXY, your HTTP client tries to reach internal service names like redis or db through the external proxy. Add NO_PROXY=localhost,127.0.0.1,redis,db (and lowercase no_proxy) to bypass the proxy for internal bridge hosts.
Can I assign 20 different proxies to 20 containers on one VPS?
Yes. Define each container service (or pass distinct .env variables) with its own http://user:pass@ip:port string.
Why set both uppercase and lowercase proxy variables?
Some Linux libraries (like libcurl) check lowercase http_proxy / https_proxy first, while Go and Node tools often check uppercase HTTP_PROXY / HTTPS_PROXY.
Assign dedicated static IPs to every Docker container
Instant unmetered Dedicated IPv4 and Static ISP proxies across 7 countries.
Buy Docker Proxies