By Leo Lin, Product Manager at FlashIP (https://www.flaship.com/), Singapore.
"I set HTTP_PROXY and docker pull still times out." I hear some version of this every month, and the cause is almost always the same: Docker doesn't have one proxy setting. It has at least three, and each one covers a different part of the pipeline. Set the wrong one and nothing changes.
Here's the map I use, with every setting checked against Docker's own documentation in November 2026.
The three places a proxy can live
-
The daemon (
dockerd). This is what talks to Docker Hub and other registries.docker pullgoes through here, and so does fetching images from registries generally. -
The client config (
~/.docker/config.json). This doesn't proxy the CLI or the engine. It injects proxy variables into new containers and builds. -
Build arguments and container env vars. Per-command overrides with
--build-argand--env.
If you remember one thing: pulls are a daemon problem, and apt-get or pip install inside a RUN step is a build problem.
1. Fix docker pull: configure the daemon
On Docker Engine (Linux), the recommended way is daemon.json, usually at /etc/docker/daemon.json:
{
"proxies": {
"http-proxy": "http://proxy.example.com:3128",
"https-proxy": "http://proxy.example.com:3128",
"no-proxy": "*.test.example.com,.example.org,127.0.0.0/8"
}
}
Then restart the daemon:
sudo systemctl restart docker
You can also use the --http-proxy / --https-proxy flags on dockerd, or environment variables in a systemd drop-in. Settings in the daemon config take precedence over environment variables. If you go the systemd route, create /etc/systemd/system/docker.service.d/http-proxy.conf:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:3128"
Environment="HTTPS_PROXY=http://proxy.example.com:3128"
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp"
Then reload and confirm it took:
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl show --property=Environment docker
Two gotchas from the docs that catch people:
-
Special characters in a systemd value must be double-escaped with
%%. A password containing#becomes%%23. If your proxy password has symbols and auth keeps failing, this is the first thing to check. -
Rootless Docker uses a different path:
~/.config/systemd/user/docker.service.d/, and you runsystemctl --userwithoutsudo.
Docker Desktop users: proxy settings in daemon.json are ignored by Desktop. Use the Proxies section in Docker Desktop's settings instead. Desktop has a separate "Containers proxy" that docker pull and Compose pulls always go through, so set that one if pulls are what's failing.
2. Fix RUN apt-get and pip install inside builds: the client config
The daemon proxy is for the daemon's own registry traffic. Commands running inside your build steps read proxy variables from their environment, so for those, add a proxies block to ~/.docker/config.json:
{
"proxies": {
"default": {
"httpProxy": "http://proxy.example.com:3128",
"httpsProxy": "http://proxy.example.com:3128",
"noProxy": "localhost,127.0.0.1,.internal.example.com"
}
}
}
Docker uses this to set HTTP_PROXY/http_proxy, HTTPS_PROXY/https_proxy and NO_PROXY/no_proxy (plus ftpProxy and allProxy if you add them) as environment variables and build arguments. No restart needed, but it only applies to new containers and builds. Anything already running keeps its old environment.
The default key applies to every daemon the client connects to. If you talk to a remote daemon that shouldn't use the proxy, add a key with that daemon's address (for example tcp://docker-daemon1.example.com) and override noProxy there.
Quick check that it works:
docker run --rm alpine sh -c 'env | grep -i _proxy'
3. One-off overrides from the command line
For a single build or run, pass the values directly:
docker build --build-arg HTTPS_PROXY="http://proxy.example.com:3128" .
docker run --env HTTPS_PROXY="http://proxy.example.com:3128" redis
HTTP_PROXY, HTTPS_PROXY, FTP_PROXY, NO_PROXY and ALL_PROXY (and their lowercase forms) are predefined build args, so you don't need an ARG line to use them.
Keep credentials out of your images
This is the part I'd tape to the monitor.
-
Don't use
ENVfor proxy settings in a Dockerfile. Docker's docs say it plainly: use build arguments instead.ENVbakes the proxy into the image, which breaks containers run elsewhere and can leak credentials. -
Don't declare
ARG HTTP_PROXYunless you mean to. By default, the predefined proxy args are kept out ofdocker historyand don't affect the build cache. Adding an explicitARG HTTP_PROXYline reverses that: the value shows up in history and changing it invalidates the cache. -
Remember env vars are inspectable. Docker warns that container environment variables are stored as plain text, can be read through the remote API, and can end up in an image via
docker commit.
That last point is why I prefer IP allowlisting for build servers when the provider supports it: no password in a URL means nothing to leak. FlashIP, for example, supports HTTP(S) and SOCKS5 and accepts either username:password or IP allowlist authentication, so a CI runner with a fixed egress IP can skip credentials entirely. If you must use a username and password, keep them in your CI secret store and pass them with --build-arg at build time.
A 60-second triage
-
docker pullfails → daemon config (or Desktop's Containers proxy). -
RUN apt-get updatefails, but pulls work →~/.docker/config.jsonor--build-arg. - Works locally, fails for an internal registry → add it to
no-proxy/NO_PROXY. - Auth errors only under systemd → check the
%%escaping.
Get the right layer and most "Docker ignores my proxy" tickets close themselves.
Top comments (0)