96 lines
2.4 KiB
Bash
Executable File
96 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Docker Proxy Configuration Script
|
|
# 用于临时配置 Docker 代理以拉取镜像
|
|
|
|
PROXY_HOST="127.0.0.1"
|
|
PROXY_PORT="7890"
|
|
PROXY_URL="http://${PROXY_HOST}:${PROXY_PORT}"
|
|
|
|
case "$1" in
|
|
enable|on)
|
|
export HTTP_PROXY="${PROXY_URL}"
|
|
export HTTPS_PROXY="${PROXY_URL}"
|
|
export NO_PROXY="localhost,127.0.0.1,192.168.1.83,*.local"
|
|
|
|
echo "✓ Docker proxy enabled"
|
|
echo " HTTP_PROXY=${HTTP_PROXY}"
|
|
echo " HTTPS_PROXY=${HTTPS_PROXY}"
|
|
echo " NO_PROXY=${NO_PROXY}"
|
|
echo ""
|
|
echo "Usage: docker pull <image>"
|
|
echo "Note: This only affects the current terminal session"
|
|
;;
|
|
|
|
disable|off)
|
|
unset HTTP_PROXY
|
|
unset HTTPS_PROXY
|
|
unset NO_PROXY
|
|
|
|
echo "✓ Docker proxy disabled"
|
|
;;
|
|
|
|
status)
|
|
if [ -n "$HTTP_PROXY" ]; then
|
|
echo "Proxy is ENABLED"
|
|
echo " HTTP_PROXY=${HTTP_PROXY}"
|
|
echo " HTTPS_PROXY=${HTTPS_PROXY}"
|
|
echo " NO_PROXY=${NO_PROXY}"
|
|
else
|
|
echo "Proxy is DISABLED"
|
|
fi
|
|
;;
|
|
|
|
test)
|
|
echo "Testing proxy connection to ${PROXY_URL}..."
|
|
if curl -s --connect-timeout 3 --proxy "${PROXY_URL}" https://www.google.com > /dev/null 2>&1; then
|
|
echo "✓ Proxy is working"
|
|
else
|
|
echo "✗ Proxy connection failed"
|
|
echo " Please check if proxy is running on ${PROXY_HOST}:${PROXY_PORT}"
|
|
fi
|
|
;;
|
|
|
|
pull)
|
|
if [ -z "$2" ]; then
|
|
echo "Usage: $0 pull <image:tag>"
|
|
exit 1
|
|
fi
|
|
|
|
export HTTP_PROXY="${PROXY_URL}"
|
|
export HTTPS_PROXY="${PROXY_URL}"
|
|
export NO_PROXY="localhost,127.0.0.1,192.168.1.83,*.local"
|
|
|
|
echo "Pulling $2 with proxy ${PROXY_URL}..."
|
|
docker pull "$2"
|
|
;;
|
|
|
|
*)
|
|
cat << EOF
|
|
Docker Proxy Configuration Tool
|
|
|
|
Usage:
|
|
$0 enable|on - Enable proxy for current terminal session
|
|
$0 disable|off - Disable proxy
|
|
$0 status - Show current proxy status
|
|
$0 test - Test proxy connection
|
|
$0 pull <image> - Pull image with proxy enabled
|
|
|
|
Examples:
|
|
source $0 enable # Enable proxy (use 'source' to affect current shell)
|
|
$0 pull nginx:latest # Pull image with proxy
|
|
$0 test # Test if proxy is working
|
|
source $0 disable # Disable proxy
|
|
|
|
Configuration:
|
|
Proxy: ${PROXY_URL}
|
|
No Proxy: localhost,127.0.0.1,192.168.1.83,*.local
|
|
|
|
Note:
|
|
- Use 'source' or '.' when enable/disable to affect current shell
|
|
- Use direct execution for 'pull' command
|
|
EOF
|
|
exit 1
|
|
;;
|
|
esac
|