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 #!/bin/bash
## Author: SuperManito ## Author: SuperManito
## Modified: 2025-10-22 ## Modified: 2025-10-23
## License: MIT ## License: MIT
## GitHub: https://github.com/SuperManito/LinuxMirrors ## GitHub: https://github.com/SuperManito/LinuxMirrors
## Website: https://linuxmirrors.cn ## Website: https://linuxmirrors.cn
@@ -423,7 +423,11 @@ function handle_command_options() {
function run_start() { function run_start() {
if [ -z "${CLEAN_SCREEN}" ]; then 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 elif [ "${CLEAN_SCREEN}" == "true" ]; then
clear clear
fi fi
@@ -1490,7 +1494,7 @@ function change_docker_registry_mirror() {
touch $File_DockerConfig touch $File_DockerConfig
fi 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 systemctl daemon-reload
if [[ "$(systemctl is-active docker 2>/dev/null)" == "active" ]]; then if [[ "$(systemctl is-active docker 2>/dev/null)" == "active" ]]; then
@@ -1559,9 +1563,9 @@ function only_change_docker_registry_mirror() {
fi fi
fi fi
[ -s "${File_DockerConfig}" ] || echo "{}" >$File_DockerConfig [ -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 else
echo -e '{\n "registry-mirrors": ["https://'"${SOURCE_REGISTRY}"'"]\n}' >$File_DockerConfig echo -e '{\n "registry-mirrors": '"$(handleRegistryMirrorsValue ${SOURCE_REGISTRY})"'\n}' >$File_DockerConfig
fi fi
## 重启服务 ## 重启服务
systemctl daemon-reload systemctl daemon-reload
@@ -1576,6 +1580,27 @@ function only_change_docker_registry_mirror() {
fi 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() { function check_installed_result() {
if command_exists docker; then if command_exists docker; then

View File

@@ -234,7 +234,7 @@ Command options(name/meaning/value):
| Name | Meaning | Value | | Name | Meaning | Value |
| :-: | :-: | :-: | | :-: | :-: | :-: |
| `--source` | Specify `Docker CE` mirror address (domain or IP) | `address` | | `--source` | Specify `Docker CE` mirror address (domain or IP) | `address` |
| `--source-registry` | Specify `Docker Registry` mirror address (domain or IP) | `address` | | `--source-registry` | Specify `Docker Registry` mirror address (domain or IP) | `address (separate multiple entries with commas)` |
| `--branch` | Specify `Docker CE` mirror repository (path) | `repo name (see docs below)` | | `--branch` | Specify `Docker CE` mirror repository (path) | `repo name (see docs below)` |
| `--branch-version` | Specify `Docker CE` mirror repository version | `version (see docs below)` | | `--branch-version` | Specify `Docker CE` mirror repository version | `version (see docs below)` |
| `--designated-version` | Specify `Docker Engine` installation version | `version (see docs below)` | | `--designated-version` | Specify `Docker Engine` installation version | `version (see docs below)` |
@@ -258,6 +258,13 @@ Command options(name/meaning/value):
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --en --source-registry registry.example.com bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --en --source-registry registry.example.com
``` ```
Can specify multiple addresses at the same time, and they must be separated by commas.
``` { .bash .no-copy }
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --en \
--source-registry "registry-1.example.com,registry-2.example.com"
```
- ### Only Switch Registry Mirror - ### Only Switch Registry Mirror
=== "Use Script for One-Click Replacement" === "Use Script for One-Click Replacement"
@@ -268,6 +275,14 @@ Command options(name/meaning/value):
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --en --only-registry bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --en --only-registry
``` ```
Lazy one-click command (using multiple addresses)
``` bash
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --en \
--only-registry \
--source-registry "docker.1ms.run,docker.1panel.live,docker.m.daocloud.io"
```
=== "Manual Replacement" === "Manual Replacement"
- Install the `jq` package - Install the `jq` package

View File

@@ -234,7 +234,7 @@ $ bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --help
| 名称 | 含义 | 选项值 | | 名称 | 含义 | 选项值 |
| :-: | :-: | :-: | | :-: | :-: | :-: |
| `--source` | 指定 `Docker CE` 源地址(域名或IP) | `地址` | | `--source` | 指定 `Docker CE` 源地址(域名或IP) | `地址` |
| `--source-registry` | 指定 `Docker` 镜像仓库地址(域名或IP) | `地址` | | `--source-registry` | 指定 `Docker` 镜像仓库地址(域名或IP) | `地址(多个用英文逗号分割)` |
| `--branch` | 指定 `Docker CE` 软件源仓库(路径) | `仓库名(详见下方文档)` | | `--branch` | 指定 `Docker CE` 软件源仓库(路径) | `仓库名(详见下方文档)` |
| `--branch-version` | 指定 `Docker CE` 软件源仓库版本 | `版本号(详见下方文档)` | | `--branch-version` | 指定 `Docker CE` 软件源仓库版本 | `版本号(详见下方文档)` |
| `--designated-version` | 指定 `Docker Engine` 安装版本 | `版本号(详见下方文档)` | | `--designated-version` | 指定 `Docker Engine` 安装版本 | `版本号(详见下方文档)` |
@@ -258,6 +258,13 @@ $ bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --help
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --source-registry registry.example.com bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --source-registry registry.example.com
``` ```
可以同时指定多个地址,需使用英文逗号进行分割
``` { .bash .no-copy }
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) \
--source-registry "registry-1.example.com,registry-2.example.com"
```
- ### 仅更换镜像仓库 - ### 仅更换镜像仓库
=== "使用脚本一键替换" === "使用脚本一键替换"
@@ -268,6 +275,14 @@ $ bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --help
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --only-registry bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --only-registry
``` ```
懒人一键命令(使用多个地址)
``` bash
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) \
--only-registry \
--source-registry "docker.1ms.run,docker.1panel.live,docker.m.daocloud.io"
```
=== "手动替换" === "手动替换"
- 安装 `jq` 软件包 - 安装 `jq` 软件包

View File

@@ -234,7 +234,7 @@ $ bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --zh-hant --help
| 名稱 | 意義 | 選項值 | | 名稱 | 意義 | 選項值 |
| :-: | :-: | :-: | | :-: | :-: | :-: |
| `--source` | 指定 `Docker CE` 軟體源位址(網域名稱或IP) | `位址` | | `--source` | 指定 `Docker CE` 軟體源位址(網域名稱或IP) | `位址` |
| `--source-registry` | 指定 `Docker` 映像倉庫位址(網域名稱或IP) | `位址` | | `--source-registry` | 指定 `Docker` 映像倉庫位址(網域名稱或IP) | `位址(多個用英文逗號分割)` |
| `--branch` | 指定 `Docker CE` 軟體源倉庫(路徑) | `倉庫名稱(詳見下方文件)` | | `--branch` | 指定 `Docker CE` 軟體源倉庫(路徑) | `倉庫名稱(詳見下方文件)` |
| `--branch-version` | 指定 `Docker CE` 軟體源倉庫版本 | `版本號(詳見下方文件)` | | `--branch-version` | 指定 `Docker CE` 軟體源倉庫版本 | `版本號(詳見下方文件)` |
| `--designated-version` | 指定 `Docker Engine` 安裝版本 | `版本號(詳見下方文件)` | | `--designated-version` | 指定 `Docker Engine` 安裝版本 | `版本號(詳見下方文件)` |
@@ -258,6 +258,13 @@ $ bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --zh-hant --help
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --zh-hant --source-registry registry.example.com bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --zh-hant --source-registry registry.example.com
``` ```
可同時指定多個地址,需使用英文逗號分割
``` { .bash .no-copy }
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --zh-hant \
--source-registry "registry-1.example.com,registry-2.example.com"
```
- ### 僅更換映像倉庫 - ### 僅更換映像倉庫
=== "使用腳本一鍵替換" === "使用腳本一鍵替換"
@@ -268,6 +275,14 @@ $ bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --zh-hant --help
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --zh-hant --only-registry bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --zh-hant --only-registry
``` ```
懶人一鍵指令(使用多個位址)
``` bash
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --zh-hant \
--only-registry \
--source-registry "docker.1ms.run,docker.1panel.live,docker.m.daocloud.io"
```
=== "手動替換" === "手動替換"
- 安裝 `jq` 軟體包 - 安裝 `jq` 軟體包

View File

@@ -648,8 +648,8 @@ Below are some advanced usage examples
``` bash ``` bash
bash <(curl -sSL https://linuxmirrors.cn/main.sh) --en \ bash <(curl -sSL https://linuxmirrors.cn/main.sh) --en \
--codename trixie \ --codename trixie \
--upgrade-software false --upgrade-software false
``` ```
- Disable the backports repository - Disable the backports repository
@@ -678,8 +678,8 @@ Below are some advanced usage examples
``` bash ``` bash
bash <(curl -sSL https://linuxmirrors.cn/main.sh) --en \ bash <(curl -sSL https://linuxmirrors.cn/main.sh) --en \
--codename testing \ --codename testing \
--upgrade-software false --upgrade-software false
``` ```
``` { .bash .no-copy title="If the script can't set the codename, you can manually replace it after running" } ``` { .bash .no-copy title="If the script can't set the codename, you can manually replace it after running" }

View File

@@ -650,8 +650,8 @@ $ bash <(curl -sSL https://linuxmirrors.cn/main.sh) --help
``` bash ``` bash
bash <(curl -sSL https://linuxmirrors.cn/main.sh) \ bash <(curl -sSL https://linuxmirrors.cn/main.sh) \
--codename trixie \ --codename trixie \
--upgrade-software false --upgrade-software false
``` ```
- 禁用 backports 仓库 - 禁用 backports 仓库
@@ -680,8 +680,8 @@ $ bash <(curl -sSL https://linuxmirrors.cn/main.sh) --help
``` bash ``` bash
bash <(curl -sSL https://linuxmirrors.cn/main.sh) \ bash <(curl -sSL https://linuxmirrors.cn/main.sh) \
--codename testing \ --codename testing \
--upgrade-software false --upgrade-software false
``` ```
``` { .bash .no-copy title="若脚本无法实现指定版本代号,你也可以在执行脚本后手动替换" } ``` { .bash .no-copy title="若脚本无法实现指定版本代号,你也可以在执行脚本后手动替换" }

View File

@@ -650,8 +650,8 @@ $ bash <(curl -sSL https://linuxmirrors.cn/main.sh) --zh-hant --help
``` bash ``` bash
bash <(curl -sSL https://linuxmirrors.cn/main.sh) --zh-hant \ bash <(curl -sSL https://linuxmirrors.cn/main.sh) --zh-hant \
--codename trixie \ --codename trixie \
--upgrade-software false --upgrade-software false
``` ```
- 停用 backports 倉庫 - 停用 backports 倉庫
@@ -680,8 +680,8 @@ $ bash <(curl -sSL https://linuxmirrors.cn/main.sh) --zh-hant --help
``` bash ``` bash
bash <(curl -sSL https://linuxmirrors.cn/main.sh) --zh-hant \ bash <(curl -sSL https://linuxmirrors.cn/main.sh) --zh-hant \
--codename testing \ --codename testing \
--upgrade-software false --upgrade-software false
``` ```
``` { .bash .no-copy title="如果腳本無法實現指定版本代號,你也可以在執行腳本後手動替換" } ``` { .bash .no-copy title="如果腳本無法實現指定版本代號,你也可以在執行腳本後手動替換" }