Created
November 14, 2025 09:01
-
-
Save QYG2297248353/364fe8da5570876219532dee17278dc7 to your computer and use it in GitHub Desktop.
快速启用关闭Docker代理
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # 一键启用/关闭 docker pull/push 的代理 | |
| CONF_FILE="/etc/systemd/system/docker.service.d/http-proxy.conf" | |
| PROXY="http://127.0.0.1:7890" | |
| enable_proxy() { | |
| echo "[Service] | |
| Environment=\"HTTP_PROXY=$PROXY\" | |
| Environment=\"HTTPS_PROXY=$PROXY\" | |
| Environment=\"NO_PROXY=localhost,127.0.0.1,registry.docker-cn.com,hub.docker.com\" | |
| " > $CONF_FILE | |
| systemctl daemon-reload | |
| systemctl restart docker | |
| echo "✅ Docker 代理已启用: $PROXY" | |
| } | |
| disable_proxy() { | |
| echo "[Service] | |
| #Environment=\"HTTP_PROXY=$PROXY\" | |
| #Environment=\"HTTPS_PROXY=$PROXY\" | |
| #Environment=\"NO_PROXY=localhost,127.0.0.1,registry.docker-cn.com,hub.docker.com\" | |
| " > $CONF_FILE | |
| systemctl daemon-reload | |
| systemctl restart docker | |
| echo "❎ Docker 代理已关闭" | |
| } | |
| case "$1" in | |
| on) | |
| enable_proxy | |
| ;; | |
| off) | |
| disable_proxy | |
| ;; | |
| status) | |
| systemctl show --property=Environment docker | |
| ;; | |
| *) | |
| echo "用法: $0 {on|off|status}" | |
| exit 1 | |
| esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment