Skip to main content
Proxy Server

Published Dec 2, 2026

How to Configure a Proxy in Docker

Configure proxies for Docker pulls, builds, containers, and Compose. Apply daemon settings, build arguments, and NO_PROXY while limiting credential exposure.

How to Configure a Proxy in Docker

Quick Answer

Docker uses different proxy configurations for image pulls, builds, and running containers. Configure Docker Engine or Docker Desktop when `docker pull` must reach a registry through a proxy. Pass predefined proxy build arguments when a `RUN` instruction needs internet access. Configure the application or container environment when requests made after startup need the proxy.

Docker client defaults can populate new builds and containers, including services created by Docker Compose. Explicit Compose values are easier to limit to one project or service. Before changing anything, identify whether the failing request comes from the host-side Docker CLI, the daemon, the selected builder, or the application inside a container.

Key Takeaways

  • `docker pull` and `docker push` use the Docker daemon or Docker Desktop proxy configuration, not a container's environment variables.
  • Commands inside Docker builds use predefined proxy build arguments or Docker client defaults. A separate BuildKit daemon may need its own proxy configuration for base-image and cache requests.
  • Running containers need proxy environment variables or application-specific proxy settings.
  • Docker Compose can inherit Docker client proxy defaults or set values explicitly for a build, a running service, or both.
  • `NO_PROXY` keeps selected local and internal destinations off the proxy route, but matching behavior varies between clients.
  • Docker normally publishes ports through network rules. When enabled, the optional `docker-proxy` process can help forward published-port traffic, but it does not configure outbound HTTP, HTTPS, or SOCKS5 requests.

Which Docker Proxy Setting Do You Need?

The correct Docker proxy configuration depends on which process makes the network request. A proxy set inside a container cannot help the Docker daemon pull that container's image.

Need proxy infrastructure for this workflow? Compare residential and mobile proxy options.

TaskProcess making the requestWhere to configure the proxy
Run `docker pull` or `docker push`Docker daemon or Docker Desktop`daemon.json`, the daemon service environment, or Docker Desktop proxy settings
Fetch base images or remote cache during a buildThe builder selected by Docker or BuildxDocker Engine or Docker Desktop for an integrated builder; the BuildKit daemon's proxy configuration for a separate builder
Run a Docker CLI command that contacts a remote service directlyDocker CLI or CLI plugin on the hostHost `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY`, or Docker Desktop's host proxy
Download packages during `docker build`Build containerPredefined proxy build arguments or Docker client proxy defaults
Call a website or API after the container startsApplication inside the containerContainer environment or the application's own proxy configuration
Build and run services with ComposeSelected builder and individual servicesDocker client proxy defaults, or `build.args` and `environment` in `compose.yaml`
Reach another service in the same Compose project directlyApplication inside the containerAdd the service name to `NO_PROXY`
Publish a container port to the hostDocker networkingPort publishing, not an outbound proxy setting

This separation explains a common Docker proxy problem: `docker pull` succeeds, but `apt`, `npm`, or `curl` fails inside a build. The registry path worked, while the build step lacked a usable proxy route.

A proxy endpoint is the hostname and port the client connects to. It is separate from the exit IP that the destination observes. Docker needs the endpoint in the layer that sends the request.

Before starting, collect the proxy endpoint, port, protocol, authentication method, and any destinations that must connect directly. If the client can use more than one protocol, compare HTTP and SOCKS5 proxies before choosing the Docker setting.

Configure Docker Engine for Registry Traffic

Configure the Docker daemon when image pulls, image pushes, or daemon-managed Swarm and registry traffic must use a proxy. This setting applies to `dockerd`. It does not configure applications inside containers or host-side Docker CLI requests.

Linux and Ubuntu: Set the Daemon Proxy

On Docker Engine 23.0 or later, merge a `proxies` entry into `/etc/docker/daemon.json`. These steps apply to regular Linux installations, including Ubuntu systems that run Docker through systemd. Keep unrelated settings already present in the file.

json

The `https-proxy` key selects the proxy used for HTTPS destinations. Its value can still start with `http://` when the connection from the daemon to the proxy uses HTTP.

Validate the complete file before restarting the daemon:

bash

An invalid file returns a nonzero exit code. Fix that error before continuing. Restarting Docker can interrupt running containers unless the deployment uses a suitable live-restore configuration, so schedule the change around the workload when necessary.

Restart Docker after the validation succeeds:

bash

Then test a pull with an image your organization permits:

bash

Docker recommends `daemon.json` for Docker Engine proxy configuration. Values in `daemon.json` or daemon flags take precedence over proxy variables inherited by the service.

Rootless Docker uses the user's configuration directory instead of `/etc/docker`. The usual daemon file is `~/.config/docker/daemon.json`. If `XDG_CONFIG_HOME` is set, use `$XDG_CONFIG_HOME/docker/daemon.json` instead. The service restarts without `sudo`:

bash

The official Docker daemon proxy documentation also describes daemon flags and a systemd drop-in for installations that use service variables or an older Engine release. Keep one authoritative method where possible. Conflicting sources make troubleshooting needlessly difficult.

Docker Desktop on Windows, macOS, and Linux

Docker Desktop ignores proxy values placed in `daemon.json`. Open Docker Desktop settings and use the Proxies controls instead.

Docker Desktop on Windows, macOS, and Linux can use the host's system proxy, a manually entered HTTP or HTTPS proxy, or no proxy. SOCKS5 support requires a Docker Business subscription.

The current Docker Desktop proxy settings separate host-level Docker Desktop traffic from container-related traffic. The Containers proxy handles image pulls. The Docker Desktop proxy acts as the fallback for pulls when a Containers proxy is not configured.

When Docker Desktop runs Windows containers, also enable Use proxy for Windows Docker daemon. That setting allows the Windows daemon to connect through Docker Desktop's internal proxy.

If the host uses a PAC file, Docker Desktop can read a statically configured PAC URL. On Windows and macOS, WPAD discovery is untested and not officially supported. Use a fixed PAC URL or an explicit proxy address when automatic discovery produces inconsistent results.

Container applications still need their own proxy configuration unless an administrator uses the Docker Business air-gapped containers feature to route their outbound traffic. A successful image pull therefore does not prove that a running application used the same route.

Host-Side Docker CLI Traffic

Some Docker CLI commands make their own network requests from the host and recognize `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY`. CLI plugins can have separate rules, while Docker Desktop can route supported CLI and extension traffic through its host-level proxy.

`docker login` does not always follow the same network path as `docker pull`. Depending on the sign-in method, authentication may use the daemon, the host-side Docker CLI, or a browser. If a pull succeeds but login or a CLI plugin fails, identify the path that produced the error before changing proxy settings.

Configure Proxies for Docker Builds

Docker builds accept predefined proxy arguments such as `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY`. They make the values available to commands that send network requests during the build without permanently defining them with `ENV`.

Docker Client Defaults for New Builds and Containers

Add the `proxies` entry to the Docker client configuration at `~/.docker/config.json`. If `DOCKER_CONFIG` points elsewhere, edit `config.json` in that directory. Merge the entry with the existing file instead of replacing authentication or context settings.

json

Docker uses these values for new builds and new containers. It creates uppercase and lowercase proxy variables automatically. Existing containers keep their current configuration, and the Docker daemon itself remains unchanged.

The client configuration also accepts `allProxy`, which creates `ALL_PROXY` and `all_proxy`. Some applications use those variables for SOCKS5, but the application still decides whether it supports `socks5://`, `socks5h://`, and proxy-side hostname resolution.

Changes take effect without restarting Docker. Authenticated proxy URLs remain in plain text in this file, and Docker injects them into container configuration. Restrict access to the file and avoid storing broad, long-lived credentials there.

Pass a Proxy to One Docker Build

For a one-off build, pass the conventional variables as predefined build arguments:

bash

Docker reads each value from the invoking shell and excludes these predefined arguments from the build cache and `docker history` by default.

Commands run during the build can read these predefined arguments without matching `ARG` instructions. Avoid declaring or interpolating them in the Dockerfile because an explicit reference can place the values in build cache metadata. Avoid persistent `ENV` instructions as well because they carry the proxy configuration into containers created from the image.

This minimal Dockerfile tests network access through a public IP-check endpoint instead of your production target:

docker

If Docker cannot pull `curlimages/curl`, check the selected builder, registry access, DNS, image reference, and the applicable daemon or Docker Desktop proxy. If the image pulls but the `RUN` instruction fails, inspect the build arguments and the network behavior of that command.

Docker's proxy build argument documentation confirms that the predefined variables are case-insensitive at the builder layer. Software executed inside the build may still have its own casing rules.

Buildx can use the local daemon, a `docker-container` builder, a Kubernetes builder, or a remote BuildKit daemon. Proxy build arguments reach commands inside build steps. A separate BuildKit daemon may also need its own proxy configuration for image, cache, or remote-context requests. Use `docker buildx ls` to identify the selected builder before changing its network settings.

Configure a Proxy for a Running Docker Container

A running container uses a proxy only when its application supports the supplied configuration. Docker can inject environment variables, but the application decides whether and how to read them.

The following command passes a proxy for HTTPS destinations to a disposable cURL container:

bash

The response should show the selected proxy's exit IP. Compare it with a direct request from the same environment before deciding whether the route changed.

Some applications read lowercase variables, some read uppercase variables, and some ignore both unless the proxy is set in application code. cURL accepts uppercase `HTTPS_PROXY` but not uppercase `HTTP_PROXY`. Pass the form documented by the actual client instead of assuming every container behaves alike.

For applications with explicit proxy settings, prefer those controls when they provide clearer protocol, authentication, timeout, and session behavior. Proxy environment variables are convenient, but their interpretation is not standardized.

An HTTP proxy can carry an HTTPS request through an HTTP CONNECT tunnel. The destination URL beginning with `https://` does not mean the proxy endpoint must also use an `https://` scheme.

Set Proxy Values in Docker Compose

Current Docker Compose releases can merge proxy defaults from the Docker client configuration into build arguments and container environments. Values declared for a service take precedence, making explicit Compose settings useful when only selected services should use the proxy.

The following service uses explicit runtime values rather than global Docker client defaults:

yaml

Set the values in the shell, then run the service:

bash

The required-value expression stops Compose when `HTTPS_PROXY` is unset or empty. Without it, the application could start without a configured proxy and connect directly if its network policy permits that route.

When the image build also needs explicit per-project values, add them under `build.args`:

yaml

The duplicate placement in this example is intentional. `build.args` applies while the image is built, and `environment` applies after the service starts. Docker client defaults can supply either layer when the project does not override them.

Compose can read values from the current shell, `.env`, `--env-file`, and other sources with defined precedence. Use `docker compose config --environment` to see the values Compose used for interpolation, but do not paste its output into tickets or logs when those values contain credentials.

The Docker Compose environment documentation recommends secrets rather than ordinary environment variables for sensitive values. A Compose secret can protect a password file, but the application must support reading that file and using the value for proxy authentication. Compose does not automatically turn a secret into `HTTPS_PROXY`. The guide to securing proxy credentials in CI/CD explains how to store and inject proxy credentials in deployment pipelines without committing them.

Configure `NO_PROXY` for Direct Connections

`NO_PROXY` lists destinations that should connect directly. It is commonly used for loopback addresses, internal registries, Compose service names, and private domains that must stay off the proxy route.

A practical starting value for a Compose service might be:

bash

Here, `api` and `db` are Compose service names. Inside a container, `localhost` refers to that same container, not the Docker host and not another service.

For the Docker daemon, `example.internal` matches the domain and its subdomains, while `.example.internal` matches subdomains only. A single `*` tells the daemon not to use a proxy for any destination. An application inside a container may follow different rules for leading dots, ports, wildcards, and IP ranges.

Test every bypass entry with the actual client. `NO_PROXY=*` can send all supported traffic directly when the deployment expected a proxy, while a missing internal hostname can send private service traffic toward the external proxy.

Keep Proxy Credentials Out of Images

Proxy authentication belongs to the component making the request. The daemon's connection to a proxy may use one proxy credential, while an application inside a container can use another. Registry credentials are separate and authenticate the user to the image registry rather than to the intermediary proxy.

Username-and-password credentials are often embedded in this proxy URL format:

bash

Percent-encode characters that would otherwise be interpreted as URL delimiters, such as `@` within a username or password. Use the provider-generated proxy URL when one is available. Never commit the resulting URL to a Dockerfile, Compose file, or repository, and never bake it into an image layer.

When both the provider and the client support an encrypted client-to-proxy connection, use the provider's verified `https://` endpoint to protect credentials in transit. If only an HTTP proxy endpoint is available, send authenticated traffic from a network you trust. HTTPS destination content can remain protected through CONNECT, but that does not encrypt an HTTP proxy credential from the client to the proxy.

Docker client proxy defaults and container environment variables are inspectable. Docker Desktop can store supported proxy credentials in the operating system credential store, but that protection does not extend automatically to an application's environment inside a container.

Use these controls where they fit the deployment:

  • Load the proxy value from a protected runtime secret store rather than source control.
  • Use narrowly scoped credentials that can be revoked without affecting unrelated workloads.
  • Prefer source-IP allowlisting when the host has a stable public egress address and the provider supports it.
  • With the proxy disabled, confirm the container's direct public egress address before creating an allowlist rule.
  • Keep management API tokens separate from proxy traffic credentials.

The proxy provider normally sees the public source address presented by the Docker host or by its upstream NAT gateway or cloud egress service. A move between networks can change that address and invalidate a source-IP allowlist.

An HTTP `407 Proxy Authentication Required` response comes from the proxy. A `401` or `403` confirmed to come from the destination means the request reached that destination but failed its authentication or access checks. The 407 troubleshooting steps help separate rejected proxy credentials from destination access failures.

Test Each Docker Network Path

Test one network layer at a time. Begin with the first request in the sequence and stop where the observed result changes.

  1. Test the daemon path: Pull a small permitted image. A failure at this step narrows the investigation to Docker Engine, Docker Desktop, registry access, DNS, or the host network.
  2. Test the build path: Run the complete build command shown earlier and inspect its plain-text progress output. The included `--no-cache` option forces the network step to execute again. If the base image pulls but a `RUN` step cannot reach its destination, investigate the build command, its proxy arguments, and the selected builder.
  3. Test the container path: Send a request from a disposable container to an IP-check service and record the returned address.
  4. Test bypass rules: Call one internal service that should match `NO_PROXY` and one external endpoint that should use the proxy.
  5. Test the intended workload: Check status, headers, required fields, location-sensitive output, and response time rather than accepting any HTTP response as success.
  6. Repeat under the required session mode: Confirm that the exit remains stable or rotates as intended.

An IP check verifies the observed route for one request. A broader proxy test also checks authentication, location, latency, reliability, and returned content.

Do not print all environment variables during production debugging. That can expose proxy passwords and unrelated application secrets. Log the configuration source, proxy hostname, non-sensitive port, response status, and timing instead.

Troubleshoot a Docker Proxy That Is Not Working

Preserve the exact error, then identify the first network layer that failed before changing settings.

SymptomMost likely layerFirst check
`docker pull` times outDaemon, Docker Desktop, DNS, or registry pathDaemon/Desktop proxy and `NO_PROXY` for the registry
Connection refusedProxy endpoint, port, firewall, or local networkExact hostname and port, then TCP reachability from the failing layer
Base image pulls, but a Dockerfile `RUN` command failsBuild containerProxy build arguments and the command's variable support
Running container shows the direct IPApplication or runtime configurationVariables passed to the container and client-specific proxy support
`407 Proxy Authentication Required`Proxy authenticationCredential source, encoding, allowlist address, and account state
Internal Compose service is sent through the proxyRuntime bypass configurationService name and domain entries in `NO_PROXY`
`docker run` works, but Compose does notCompose interpolation or precedenceShell values, `.env`, `--env-file`, and resolved service environment
Works on Linux, but not Docker DesktopDifferent configuration ownerDocker Desktop Proxies settings rather than `daemon.json`
TLS verification failsClient trust or authorized inspectionFailing certificate chain and CA trust inside the correct layer
Variables are present, but requests remain directApplication behaviorExact variable casing or explicit proxy option supported by the client
Only some destinations failBypass rule, destination policy, or route availabilityResolved hostname, target response, provider limits, and authorization

Do not fix TLS errors by disabling certificate verification. Identify whether the failing certificate belongs to the registry, destination, proxy, or an authorized inspection system, then add the correct CA to the component that needs it.

A command-line baseline using cURL with a proxy can confirm the endpoint outside Docker. Match the protocol, hostname, port, authentication, and destination before comparing results.

Is docker-proxy the Same as an Outbound Proxy?

No. Docker normally publishes container ports through firewall NAT and PAT rules. When the optional userland proxy is enabled, `docker-proxy` can help forward some published-port traffic between the host and a container. Neither mechanism configures a forward proxy for web requests leaving a build or container.

For example, `docker run -p 8080:80 app` publishes a container port. It says nothing about how `app` reaches an external website. Outbound HTTP, HTTPS, or SOCKS5 routing still belongs in the daemon, build, container, or application configuration described above.

The shared name can send troubleshooting in the wrong direction. State whether the problem concerns Docker port publishing or an outbound proxy endpoint.

Use Proxidize With Docker

Applications running in Docker can connect through Proxidize when their clients support the selected proxy protocol. Configure the container with the generated endpoint, port, and authentication method. Dashboard and API controls manage the proxy service but do not replace the credentials used for proxy traffic.

Use an HTTP proxy endpoint for applications that read `HTTP_PROXY` or `HTTPS_PROXY`. Use SOCKS5 only when the application explicitly supports it, because Docker does not translate HTTP proxy variables into SOCKS5 behavior.

A practical setup follows this order:

  1. Choose Residential Per GB, Mobile Per GB, or Mobile Per Proxy according to the required network, geography, sessions, and billing model.
  2. For a Per GB plan, create an access point and choose its available protocol, targeting, authentication, and random or sticky behavior.
  3. For Mobile Per Proxy, select an assigned proxy and configure its location, authentication, and rotation controls before copying the connection details.
  4. Copy the generated connection details into protected runtime or deployment configuration.
  5. Pass the proxy only to the service that needs it, then test the route from inside that container.
  6. Monitor valid results, bandwidth, latency, and retries before increasing traffic.

Choose Proxidize Residential Proxies for global web scraping, price monitoring, SEO monitoring, AI data collection, or research that needs country, city, or ISP targeting. Rotating and sticky sessions allow independent requests and stateful tasks to use different routing behavior without rebuilding the image.

Choose Proxidize Mobile Proxies when an approved workload specifically needs a United States mobile-network route. Mobile Per GB suits variable traffic through a pool, while Mobile Per Proxy suits a known set of assigned mobile proxies with direct rotation controls.

The Proxidize proxy API manages supported infrastructure settings. Its bearer token is not a proxy password and should never be placed in `HTTP_PROXY` or `HTTPS_PROXY`.

Start a Proxidize trial with a small container test. Validate the route and returned data before increasing traffic.

Frequently asked questions

Docker Engine commonly reads daemon proxy settings from `/etc/docker/daemon.json`. Rootless Docker commonly uses `~/.config/docker/daemon.json`, or `$XDG_CONFIG_HOME/docker/daemon.json` when that variable is set. Docker client defaults for new builds and containers live in `~/.docker/config.json` or the directory selected by `DOCKER_CONFIG`. Docker Desktop uses its settings interface instead of daemon proxy values in `daemon.json`.

Configure the Docker daemon or Docker Desktop because that process performs the image pull. A proxy environment variable passed only to a running container cannot affect `docker pull`. Restart Docker Engine after changing `daemon.json`; Docker Desktop applies settings through its own interface.

Pass `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` as predefined build arguments. Do not store proxy URLs with `ENV`, because those values persist in the image configuration. The predefined proxy arguments need no matching `ARG` instructions and stay out of `docker history` unless referenced in the Dockerfile.

Docker Desktop can use the host's system proxy when that mode is selected. A standalone Docker Engine needs a daemon configuration for daemon traffic, while applications inside containers need client defaults, container variables, or application-specific settings. Test the host, daemon, builder, and runtime paths separately.

Docker Desktop currently supports SOCKS5 with a Business subscription. A containerized application can use SOCKS5 when its own client supports that protocol. Docker client configuration can create `ALL_PROXY` and `all_proxy` from `allProxy`, but each application still determines which SOCKS schemes and DNS behavior it accepts.

Compose can receive proxy defaults from the Docker client configuration or explicit values from the Compose project. For interpolated values, inspect the shell, `.env`, `--env-file`, and Compose precedence. Then confirm that the resolved service environment or build arguments contain the intended non-secret settings and that the application recognizes the chosen variable name.