Docker proxy settings: daemon, build and container
Originally published on proxymint.
Docker proxy settings live in three places: daemon.json for pulls, build args for builds, config.json for containers. Tested traps, leaks and fixes.
TL;DR
- Your shell's HTTPS_PROXY does nothing for docker pull. The daemon does the pull, so the proxy goes in /etc/docker/daemon.json under proxies, then a restart; docker info | grep -i proxy tells you whether it took.
- Containers don't inherit the daemon's proxy. Put a proxies block in ~/.docker/config.json and every new container and build gets HTTP_PROXY, HTTPS_PROXY and NO_PROXY in both cases, which is the part people forget after fixing pulls.
- Don't put the proxy in ENV or ARG in a Dockerfile. Plain --build-arg HTTPS_PROXY stays out of docker history, but an ARG HTTPS_PROXY line wrote the password into the history in the test, even with no step using it.
- -e HTTPS_PROXY only replaces the uppercase copy. With config.json set, the lowercase https_proxy keeps the old value, and curl and Python read that one, so pass both cases or edit config.json instead.
Key takeaways
- Fix pulls in daemon.json, not in your shell. Use http:// for both keys, restart the daemon, and allow registry-1.docker.io, auth.docker.io and the blob CDN host, or layers stall after the manifest resolves.
- Use config.json for builds and containers. It sets six variables per container with no restart, though existing containers keep their old environment until you recreate them.
- Point containers at an address they can reach. 127.0.0.1 inside a container is the container; use the bridge gateway, host.docker.internal with --add-host=host.docker.internal:host-gateway, or --network host.
- Install curl in Alpine images that call HTTPS. busybox wget asked the proxy for GET https:// instead of a CONNECT tunnel and failed with wget: error getting response on Alpine 3.20 and 3.24.
- Check each layer with one command. docker info for pulls, a RUN env step for builds and docker run env for containers find the broken layer in a minute.
Read the full guide on proxymint, with the commands, tables and sources.
原文:https://www.a8q9.cn/en/article/docker-proxy-settings-daemon-build-and-container-9bde78.html