Docker 脚本指定镜像仓库命令选项新增支持指定多个地址

This commit is contained in:
Super Manito
2025-10-23 05:35:17 +08:00
parent 06bc87f75e
commit 51be34be62
7 changed files with 90 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/bash
## Author: SuperManito
## Modified: 2025-10-22
## Modified: 2025-10-23
## License: MIT
## GitHub: https://github.com/SuperManito/LinuxMirrors
## Website: https://linuxmirrors.cn
@@ -423,7 +423,11 @@ function handle_command_options() {
function run_start() {
if [ -z "${CLEAN_SCREEN}" ]; then
[[ -z "${SOURCE}" || -z "${SOURCE_REGISTRY}" ]] && clear
if [[ "${ONLY_REGISTRY}" == "true" ]]; then
[[ -z "${SOURCE_REGISTRY}" ]] && clear
else
[[ -z "${SOURCE}" || -z "${SOURCE_REGISTRY}" ]] && clear
fi
elif [ "${CLEAN_SCREEN}" == "true" ]; then
clear
fi
@@ -1490,7 +1494,7 @@ function change_docker_registry_mirror() {
touch $File_DockerConfig
fi
echo -e '{\n "registry-mirrors": ["https://'"${SOURCE_REGISTRY}"'"]\n}' >$File_DockerConfig
echo -e '{\n "registry-mirrors": '"$(handleRegistryMirrorsValue ${SOURCE_REGISTRY})"'\n}' >$File_DockerConfig
## 重启服务
systemctl daemon-reload
if [[ "$(systemctl is-active docker 2>/dev/null)" == "active" ]]; then
@@ -1559,9 +1563,9 @@ function only_change_docker_registry_mirror() {
fi
fi
[ -s "${File_DockerConfig}" ] || echo "{}" >$File_DockerConfig
jq '.["registry-mirrors"] = ["https://'"${SOURCE_REGISTRY}"'"]' $File_DockerConfig >$File_DockerConfig.tmp && mv $File_DockerConfig.tmp $File_DockerConfig
jq '.["registry-mirrors"] = '"$(handleRegistryMirrorsValue ${SOURCE_REGISTRY})"'' $File_DockerConfig >$File_DockerConfig.tmp && mv $File_DockerConfig.tmp $File_DockerConfig
else
echo -e '{\n "registry-mirrors": ["https://'"${SOURCE_REGISTRY}"'"]\n}' >$File_DockerConfig
echo -e '{\n "registry-mirrors": '"$(handleRegistryMirrorsValue ${SOURCE_REGISTRY})"'\n}' >$File_DockerConfig
fi
## 重启服务
systemctl daemon-reload
@@ -1576,6 +1580,27 @@ function only_change_docker_registry_mirror() {
fi
}
function handleRegistryMirrorsValue() {
local content="$1"
local delimiter=","
local result=""
content="$(echo "${content}" | sed 's| ||g')"
local -a items=(${content//,/ })
for item in "${items[@]}"; do
[[ -z "${item}" ]] && continue
if [[ -z "${result}" ]]; then
result='"https://'"${item}"'"'
else
result="${result},\"https://${item}\""
fi
done
if [[ "${result}" ]]; then
echo "[${result}]"
else
echo ""
fi
}
## 查看版本并验证安装结果
function check_installed_result() {
if command_exists docker; then