feat: init project
This commit is contained in:
commit
870a0c58d1
3 files changed
+168
No files matched your search
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
MIRRORS=(
|
||||
"https://docker.1ms.run"
|
||||
"https://docker.xuanyuan.me"
|
||||
"https://docker.m.daocloud.io"
|
||||
"https://dockerproxy.com"
|
||||
"https://docker.nju.edu.cn"
|
||||
)
|
||||
|
||||
DAEMON_JSON="/etc/docker/daemon.json"
|
||||
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "Please run as root (sudo)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Backup existing config
|
||||
if [ -f "$DAEMON_JSON" ]; then
|
||||
cp "$DAEMON_JSON" "${DAEMON_JSON}.bak.$(date +%s)"
|
||||
fi
|
||||
|
||||
# Build mirrors JSON array
|
||||
MIRRORS_JSON=$(printf '%s\n' "${MIRRORS[@]}" | jq -R . | jq -s .)
|
||||
|
||||
# Merge with existing config if present
|
||||
if [ -f "$DAEMON_JSON" ]; then
|
||||
jq --argjson mirrors "$MIRRORS_JSON" '. + {"registry-mirrors": $mirrors}' "$DAEMON_JSON" > "${DAEMON_JSON}.new"
|
||||
else
|
||||
jq -n --argjson mirrors "$MIRRORS_JSON" '{"registry-mirrors": $mirrors}' > "${DAEMON_JSON}.new"
|
||||
fi
|
||||
|
||||
mv "${DAEMON_JSON}.new" "$DAEMON_JSON"
|
||||
echo "Wrote $DAEMON_JSON"
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl restart docker
|
||||
|
||||
echo "Docker mirrors configured. Verify: docker info | grep -A5 Mirrors"
|
||||
Reference in new issue
Block a user