Configuring proxies in config.json randomizes environment-variable order
@thaJeztah is already working on this.
Since Apr 23, 2025.
- Dominant language
- Go
- Stars
- 6.1k
- Forks
- 2.2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
Noticed this when working on https://github.com/docker/cli/pull/1573
I have a fix (and some refactoring for this); still cleaning it up a bit, but will open a PR after that
When specifying environment variables, the order in which the variables are set is preserved;
docker run --rm --env no_proxy=one --env NO_PROXY=two --env HTTPS_PROXY=three busybox env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=8f03e5a9a4d1
no_proxy=one
NO_PROXY=two
HTTPS_PROXY=three
HOME=/root
docker run --rm --env no_proxy=one --env NO_PROXY=two --env HTTPS_PROXY=three busybox env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=8f03e5a9a4d1
no_proxy=one
NO_PROXY=two
HTTPS_PROXY=three
HOME=/root
However, when configuring proxies in the config.json configuration file, those proxy-settings are merged with environment-variables set on the command-line, causing their order to be randomized;
echo '{ "proxies": {"default": { "httpProxy": "four" }}}' > config.json
docker --config=./ run --rm --env no_proxy=one --env NO_PROXY=two --env HTTPS_PROXY=three busybox env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=f9b54b5489fa
no_proxy=one
NO_PROXY=two
HTTPS_PROXY=three
HTTP_PROXY=four
http_proxy=four
HOME=/root
docker --config=./ run --rm --env no_proxy=one --env NO_PROXY=two --env HTTPS_PROXY=three busybox env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=8e7b6b848827
HTTPS_PROXY=three
HTTP_PROXY=four
http_proxy=four
no_proxy=one
NO_PROXY=two
HOME=/root
The problem is caused by ParseProxyConfig converting the environment variables to a map, and Golang (by design) randomizes the order of maps when iterating over them.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.