Docker Proxy Settings for Build and Runtime

Docker proxy settings let you route container traffic through RotatingProxy's gateway for both building images and running containers. You configure this using the HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables in Docker's daemon configuration or directly in docker run and docker build commands.

Key points
  • Set HTTP_PROXY=http://USERNAME:PASSWORD@gw.rotatingproxy.cc:7070 for Docker daemon and container runtime.
  • Use the Docker client config or command-line flags to pass proxy settings to the docker build command.
  • Target countries, cities, or use sticky sessions by adding options like _cc.us or _sid.abc123 to the proxy username.
  • Common issues include 407 errors from incorrect auth and timeouts from blocked ports or DNS.

Docker Proxy Settings Overview

Docker proxy settings control how the Docker daemon and your containers access the internet, which is essential when you need to route traffic through a rotating proxy service like ours. The configuration happens at two levels: the Docker daemon itself (for operations like pulling images) and within individual containers (for your application's outbound requests). You manage these settings primarily through environment variables: HTTP_PROXY, HTTPS_PROXY, and NO_PROXY. This guide covers how to apply these variables for both build and runtime when using RotatingProxy's gateway at gw.rotatingproxy.cc on ports 7070 (HTTP/HTTPS) or 7071 (SOCKS5).

Configuring the Docker Daemon for Proxy Access

To make the Docker daemon use a proxy for pulling base images from Docker Hub or other registries, you must edit the daemon's configuration file. On Linux, this is typically /etc/docker/daemon.json; on Docker Desktop for Mac or Windows, you access these settings through the GUI. You need to add environment variable definitions in a specific format. Here is an example daemon.json configuration that routes the daemon's HTTP and HTTPS traffic through RotatingProxy's HTTP gateway with authentication:

{
  "proxies": {
    "default": {
      "httpProxy": "http://USERNAME:PASSWORD@gw.rotatingproxy.cc:7070",
      "httpsProxy": "http://USERNAME:PASSWORD@gw.rotatingproxy.cc:7070",
      "noProxy": "localhost,127.0.0.1,*.local"
    }
  }
}

Replace USERNAME and PASSWORD with the credentials of a proxy user you created in your dashboard. After saving the file, restart the Docker daemon with sudo systemctl restart docker on Linux. The daemon will now use this proxy for all its outgoing HTTP/HTTPS traffic. Note that this does not automatically apply the proxy to containers you run; that requires separate configuration covered in the next section.

Setting HTTP_PROXY for Container Runtime

To direct your application's traffic from inside a container through the proxy, you pass the environment variables at container runtime. The most straightforward method is using the -e flag with docker run. For example, to run a simple Alpine Linux container and curl an external IP check service through the proxy, use:

docker run --rm -e HTTP_PROXY="http://USERNAME:PASSWORD@gw.rotatingproxy.cc:7070" -e HTTPS_PROXY="http://USERNAME:PASSWORD@gw.rotatingproxy.cc:7070" alpine/curl -s https://api.ipify.org

This command sets both HTTP_PROXY and HTTPS_PROXY for the container's environment. Many HTTP client libraries in languages like Python, Node.js, and Go automatically respect these variables. For complex applications, you can define these variables in your Dockerfile using the ENV instruction, but this bakes the proxy credentials into the image, which is not recommended for security. A better practice is to use Docker Compose and inject the variables from an environment file or the host's environment at runtime.

Docker Build Proxy Configuration

During the docker build process, commands like RUN apt-get update or RUN pip install need internet access. To route this build-time traffic through the proxy, you must pass build arguments. Use the --build-arg flag to set the proxy environment variables for the build context. Here is an example Dockerfile snippet and build command:

# Dockerfile
FROM python:3.11-slim
ARG http_proxy
ARG https_proxy
ENV HTTP_PROXY=${http_proxy} HTTPS_PROXY=${https_proxy}
RUN pip install --no-cache-dir requests httpx

# Build command
docker build --build-arg http_proxy="http://USERNAME:PASSWORD@gw.rotatingproxy.cc:7070" --build-arg https_proxy="http://USERNAME:PASSWORD@gw.rotatingproxy.cc:7070" -t myapp .

The ARG instructions make the proxy settings available during the build, and the ENV instructions can set them for subsequent RUN commands. Note that some tools like apt-get may require additional configuration in a RUN command to use the proxy; check the current docs for your base image. For a comprehensive guide on using proxies with package managers, see our page on npm and pip behind a proxy.

Adding Targeting and Sticky Sessions

RotatingProxy allows geo-targeting and session control through options appended to the username. You include these options when constructing the proxy URL for your Docker settings. For instance, to target residential IPs in the United States, specifically Chicago, with a sticky session lasting 30 minutes, you would build a username like USERNAME_net.res_cc.us_city.chicago_sid.a7k2m9_ttl.30. Use this full string as the username part in your HTTP_PROXY environment variable:

export PROXY_URL="http://USERNAME_net.res_cc.us_city.chicago_sid.a7k2m9_ttl.30:PASSWORD@gw.rotatingproxy.cc:7070"
docker run --rm -e HTTP_PROXY="${PROXY_URL}" -e HTTPS_PROXY="${PROXY_URL}" your-app-image

This ensures all outbound requests from the container exit from IPs in the chosen location, and with the session ID (sid.), the IP will remain the same for the specified TTL as long as the connection is reused. For tasks like price monitoring or rank tracking, maintaining a consistent session can be important.

Using the SOCKS5 Port in Docker

While the HTTP proxy port 7070 works for most web traffic, some applications or libraries may prefer or require a SOCKS5 proxy. RotatingProxy provides SOCKS5 on port 7071. However, the standard HTTP_PROXY environment variable only works for HTTP proxies. To use SOCKS5 in Docker, you typically need to configure your application's client library directly, as environment variables are not a universal standard for SOCKS. For example, in a Python container using the requests library, you would set the proxy within your code, not via the container's environment. You can find specific setup instructions in our Python requests proxy guide. If your application supports SOCKS5 via an environment variable like ALL_PROXY=socks5://..., you can set it at runtime similarly. Verify your client library's documentation for SOCKS5 support.

Verifying the Exit IP from a Container

After configuring the proxy, you should verify that traffic is exiting through RotatingProxy and that the IP matches your targeting options. A quick test is to run a container with curl or wget and query an IP echo service. Using the proxy environment variables, run:

docker run --rm -e HTTP_PROXY="http://USERNAME_net.res_cc.us:PASSWORD@gw.rotatingproxy.cc:7070" -e HTTPS_PROXY="http://USERNAME_net.res_cc.us:PASSWORD@gw.rotatingproxy.cc:7070" alpine/curl -s https://ipinfo.io/json | grep ip

This should return an IP from the United States. For more detailed location data, you can parse the full JSON response. This verification step is crucial when setting up proxies for checking geo-restricted content or localization testing. If the IP does not match your expected country, double-check the username options, particularly the country code (cc.). Our checking the exit IP and location page lists more services you can use.

Common Docker Proxy Errors and Fixes

When using Docker proxy settings, you might encounter a few common errors. A 407 Proxy Authentication Required error means your login details were not accepted by the proxy gateway. This often happens if the username or password is mistyped, or if the underscore-separated options in the username are formatted incorrectly. Ensure there are no spaces and that the full string is URL-encoded properly if needed (though in environment variables, usually it's fine). Timeouts or connection refused errors can mean the Docker host cannot reach gw.rotatingproxy.cc:7070. Check your host's firewall and network configuration. Also, remember that the proxy only supports IPv4; if your host defaults to IPv6 for DNS, it may fail to resolve the gateway hostname. Force IPv4 resolution if necessary. For a deeper dive on error 407, see proxy error 407 authentication required.

Tips for Running at Scale with Docker

When orchestrating many containers that use rotating proxies, plan for concurrency and session management. Each proxy user supports up to 1,000 concurrent connections across your account. If you are running hundreds of containers, ensure you are not exceeding this limit, as detailed in how many connections can I open. To distribute traffic and avoid linkability, use different proxy user logins or session IDs for different containers or tasks. For example, in a microservices setup for ecommerce data proxies, you might assign a unique session ID per product category scraper. Monitor your traffic usage per proxy user via the dashboard to stay within any monthly GB caps you've set. Also, consider that build-time proxy usage counts toward your traffic balance; large docker build operations that pull many packages can consume GBs. Use layer caching and minimize the number of RUN commands that require network access to reduce costs, as outlined in how to reduce proxy traffic costs.

Docker Compose and Environment Files

For production deployments, using Docker Compose with environment files keeps your proxy configuration manageable and secure. Create a .env file (add it to .gitignore) with your proxy credentials and options:

# .env file
ROTATINGPROXY_USER=USERNAME_net.res_cc.de
ROTATINGPROXY_PASS=PASSWORD
PROXY_URL=http://${ROTATINGPROXY_USER}:${ROTATINGPROXY_PASS}@gw.rotatingproxy.cc:7070

Then, in your docker-compose.yml, reference these environment variables:

version: '3.8'
services:
  scraper:
    image: my-scraper:latest
    environment:
      - HTTP_PROXY=${PROXY_URL}
      - HTTPS_PROXY=${PROXY_URL}
      - NO_PROXY=localhost,internal-api
    # ... other settings

Run docker-compose up and Compose will substitute the values. This method separates configuration from code and allows easy switching between proxy networks (e.g., to mobile proxies for mobile app testing) by changing the _net.mob option in the .env file. For more on choosing a network, read which network to choose.

Networking and NO_PROXY Settings

The NO_PROXY environment variable is essential to prevent routing internal traffic through the external proxy, which would cause delays or failures. In Docker environments, you often have inter-container communication via service names. List these internal hosts, along with localhost and any internal IP ranges, in NO_PROXY. For example, in a Kubernetes sidecar pattern or a Compose setup with multiple services, you might set NO_PROXY=localhost,127.0.0.1,backend-service,redis,10.0.0.0/8. The syntax accepts domain suffixes (e.g., .mycompany.internal), IP addresses, and CIDR ranges. Setting this correctly ensures your application can still reach internal databases and APIs directly while routing all external web requests through RotatingProxy for tasks like news monitoring or financial data collection.

Questions

Can I assign different proxy locations to different containers within a single Docker Compose file?

Yes, you can define separate environment variables for each service in your docker-compose.yml. For example, assign one service HTTP_PROXY with a _cc.us target and another with a _cc.de target. This lets you parallelize geo-specific tasks like market research across regions.

Why does my Docker build fail with a 502 error when using the proxy?

A 502 Bad Gateway from the proxy usually indicates a temporary issue with the exit node. This can happen with any rotating network. The build command should implement a retry strategy. Ensure your Dockerfile's RUN commands use retry logic (like `--retry 3` for curl or wget) or run the build again.

How do I configure a proxy for Docker on Windows without editing daemon.json?

In Docker Desktop for Windows, go to Settings > Resources > Proxies. You can enter the HTTP and HTTPS proxy URLs there directly, using the same format: http://USERNAME:PASSWORD@gw.rotatingproxy.cc:7070. This configures the daemon. For containers, you still need to set environment variables per container.

Will using a proxy slow down my docker pull commands?

There is some added latency because traffic routes through our gateway. However, for pulling images, the impact is often minimal after the initial connection. The larger factor is the geographical distance between the exit node and the Docker registry. Choose a proxy country close to the registry (like _cc.us for Docker Hub's US mirrors) to reduce latency.

Can I use the proxy with Docker Swarm or Kubernetes pods?

Yes, you can set the HTTP_PROXY environment variable in your pod or service specifications. In Kubernetes, define it in the pod's env section. In Docker Swarm, you can set it in the service's environment. This routes the container's outbound traffic through the proxy, useful for website uptime and change monitoring from different locations.

My application inside the container ignores HTTP_PROXY. What should I check?

Not all libraries or tools respect these variables. Verify your application's HTTP client documentation. For example, some native Go binaries or custom C++ apps may need explicit proxy configuration. You may need to pass proxy settings as command-line arguments or configuration files to the app instead of relying on the environment. Check our integration guides for your specific stack, like Go HTTP proxy.

Start with one top-up, use any network

Create an account in a minute, add $40 or more, and the same balance pays for residential, mobile, datacenter and ISP traffic.