A daemon.json file may already contain DNS, storage or logging settings. Changing the proxy should preserve those keys.

With Mike Farah’s yq v4, assign the individual fields and write a separate candidate:

http_proxy='http://proxy.example:8080' \
https_proxy='http://proxy.example:8080' \
no_proxy='localhost,127.0.0.1,.internal.example' \
yq -o=json '
  .proxies."http-proxy" = strenv(http_proxy) |
  .proxies."https-proxy" = strenv(https_proxy) |
  .proxies."no-proxy" = strenv(no_proxy)
' /etc/docker/daemon.json > daemon.proxy-candidate.json

The HTTP proxy list offers candidates for the two HTTP URL values when public registry traffic may use public intermediaries; retain the internal bypasses. strenv reads each value as a string. env instead parses YAML values, which is unnecessary for these URL and bypass fields. The environment-variable name inside strenv has no dollar prefix.

Assigning three fields preserves other members of proxies as well as unrelated top-level settings. The -o=json option keeps the output in the format Docker expects. Another program called yq can have a different expression language.

Review the candidate before replacing the active file through the machine’s normal configuration process. Writing straight back to the input with shell redirection can truncate it before yq reads it.

These hyphenated field names configure Docker Engine’s daemon. Docker Desktop uses its own proxy settings, and the CLI’s container-environment proxy object has another schema.

Tënë sô zo