Why Your Proxy Works on the Host but Fails in Docker
A successful proxy test on your host tells you the host can reach the proxy gateway. Run the same check inside Docker to see which network route and settings your application actually uses.
Find the first Docker command that fails
Start with the exact error. A proxy can work in a host terminal while Docker uses a different network path, proxy configuration or certificate store. Check which Docker context is active with docker context show. With a remote context, the containers run on the remote Docker host, so compare against that machine’s network when diagnosing a local proxy address.
- Image pull. If
docker pullfails before a container starts, check registry connectivity and the proxy used by Docker Engine. On Docker Desktop, check the proxy settings in Desktop. Passing--envto a container applies after this phase. Docker Engine proxy settings and Docker Desktop proxy settings - Image build. For failure while resolving a base image in
FROM, check the builder’s registry access. For failure during a DockerfileRUNinstruction such as a package download, check the predefined proxy build arguments. Use--build-argas appropriate and keep proxy credentials out of DockerfileENVinstructions. Docker build proxy arguments - Container runtime. If the image is available and the application starts, check the network and proxy settings that are present inside the running container. The tests below isolate that phase.
Compare a direct request with a proxied request
Run a direct check on the host. On Windows PowerShell, use curl.exe if curl refers to a PowerShell command. Then pull the test image separately so a registry error is easy to identify.
curl --disable --noproxy "*" --fail --silent --show-error --max-time 20 https://testmyproxies.com/api/my-ip
docker pull curlimages/curl
docker run --rm --pull=never curlimages/curl --disable --noproxy "*" --fail --silent --show-error --max-time 20 https://testmyproxies.com/api/my-ip
Compare the ip values. A host and its container may share an outward IP, so that match alone tells you little about proxy use. For the next command, replace the example hostname and port with a credential-free test endpoint you can use. The proxy setting is for an HTTPS destination and the proxy itself speaks HTTP in this example.
docker run --rm --pull=never --env "https_proxy=http://proxy.example:3128" --env "no_proxy=" --env "NO_PROXY=" curlimages/curl --disable --fail --silent --show-error --max-time 20 https://testmyproxies.com/api/my-ip
Compare the resulting IP with the proxy exit you expect. A proxy hostname resolution error or connection refusal points to the container’s route to the proxy. A 407 during the HTTP tunnel setup points to proxy authentication. If the curl test works in a default container and the app still fails, compare it on the app’s Docker network and check the app’s own proxy configuration. More curl proxy checks
Check localhost and the runtime environment
On a standard Docker bridge network, 127.0.0.1 inside the container points to the container itself. On Docker Desktop, try host.docker.internal as the proxy hostname for a service on the Docker host. On Linux Docker Engine, add the host alias explicitly. Use the actual listening port.
docker run --rm --pull=never --add-host host.docker.internal=host-gateway --env "https_proxy=http://host.docker.internal:3128" --env "no_proxy=" --env "NO_PROXY=" curlimages/curl --disable --fail --silent --show-error --max-time 20 https://testmyproxies.com/api/my-ip
On Linux, a host proxy bound only to loopback can still refuse the gateway connection. Check that the proxy listens on an interface reachable from the Docker network and that your firewall permits the intended clients. Docker Desktop host access and Linux host gateway mapping
Exporting https_proxy in a terminal sets it for that shell’s child processes. For a container, pass the variable with docker run --env https_proxy, set it in your service configuration, or check Docker’s client proxy defaults for newly created containers. Review NO_PROXY and no_proxy for entries that bypass the destination, especially *. Match the behavior of the application’s HTTP library. Keep credential-bearing proxy values out of commands you share and use your deployment’s secret handling. Docker container proxy configuration and curl proxy environment variables
Check the container’s certificate trust
If the proxy connects and curl reports a certificate error, check which connection is failing. An organization’s TLS-inspecting proxy can use a root certificate your host already trusts. The container image and the application may each use a separate CA bundle. Use an approved root from the organization that operates the proxy and configure the trust store used by the app. Retry with verification enabled. Docker CA certificate setup
When curl succeeds and your Python app still fails, check whether Requests is using the same proxy and CA bundle. Test the request with Python Requests