From 54530ea3d320569fcac7401546c142639cae7197 Mon Sep 17 00:00:00 2001 From: Joe Zheng Date: Fri, 6 Sep 2024 23:14:14 +0800 Subject: [PATCH] dockerd: add config options for http proxy add config options to set http porxy for dockerd, refer to https://docs.docker.com/engine/daemon/proxy/ for details use the *_proxy environment variable as the default value, so in most cases, dockerd can use the system proxy settings just like opkg. Signed-off-by: Joe Zheng (cherry picked from commit e795bab253253e260b61e156d5e5c00e8189cb98) --- utils/dockerd/files/dockerd.init | 11 +++++++++++ utils/dockerd/files/etc/config/dockerd | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/utils/dockerd/files/dockerd.init b/utils/dockerd/files/dockerd.init index 6086b51952..51889370ca 100755 --- a/utils/dockerd/files/dockerd.init +++ b/utils/dockerd/files/dockerd.init @@ -185,6 +185,10 @@ process_config() { config_get ip globals ip "" config_get fixed_cidr globals fixed_cidr "" config_get fixed_cidr_v6 globals fixed_cidr_v6 "" + # Use the *_proxy environment variable as the default value + config_get http_proxy proxies http_proxy "${http_proxy}" + config_get https_proxy proxies https_proxy "${https_proxy}" + config_get no_proxy proxies no_proxy "${no_proxy}" . /usr/share/libubox/jshn.sh json_init @@ -207,6 +211,13 @@ process_config() { [ -z "${ip}" ] || json_add_string "ip" "${ip}" [ -z "${fixed_cidr}" ] || json_add_string "fixed-cidr" "${fixed_cidr}" [ -z "${fixed_cidr_v6}" ] || json_add_string "fixed-cidr-v6" "${fixed_cidr_v6}" + if [ -n "${http_proxy}" ] || [ -n "${https_proxy}" ] || [ -n "${no_proxy}" ]; then + json_add_object "proxies" + [ -z "${http_proxy}" ] || json_add_string "http-proxy" "${http_proxy}" + [ -z "${https_proxy}" ] || json_add_string "https-proxy" "${https_proxy}" + [ -z "${no_proxy}" ] || json_add_string "no-proxy" "${no_proxy}" + json_close_object + fi json_dump > "${DOCKERD_CONF}" [ "${iptables}" -eq "1" ] && config_foreach iptables_add_blocking_rule firewall diff --git a/utils/dockerd/files/etc/config/dockerd b/utils/dockerd/files/etc/config/dockerd index dd7523543c..0fa4a5627d 100644 --- a/utils/dockerd/files/etc/config/dockerd +++ b/utils/dockerd/files/etc/config/dockerd @@ -21,6 +21,13 @@ config globals 'globals' # list registry_mirrors 'https://' # list registry_mirrors 'https://hub.docker.com' +# If your organization uses a proxy server to connect to the internet, you may need to configure the proxy. +# See https://docs.docker.com/engine/daemon/proxy/ for more details +config proxies 'proxies' +# option http_proxy 'http://proxy.example.com:3128' +# option https_proxy 'https://proxy.example.com:3129' +# option http_proxy '*.test.example.com,.example.org,127.0.0.0/8' + # Docker doesn't work well out of the box with fw4. This is because Docker relies on a compatibility layer that # naively translates iptables rules. For the best compatibility replace the following dependencies: # `firewall4` -> `firewall` -- 2.30.2