mirror of
https://gitee.com/SuperManito/LinuxMirrors
synced 2025-11-03 07:50:28 +08:00
Docker 脚本指定镜像仓库命令选项新增支持指定多个地址
This commit is contained in:
@@ -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
|
||||
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
|
||||
|
||||
@@ -234,7 +234,7 @@ Command options(name/meaning/value):
|
||||
| Name | Meaning | Value |
|
||||
| :-: | :-: | :-: |
|
||||
| `--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-version` | Specify `Docker CE` mirror repository 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
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
=== "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
|
||||
```
|
||||
|
||||
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"
|
||||
|
||||
- Install the `jq` package
|
||||
|
||||
@@ -234,7 +234,7 @@ $ bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --help
|
||||
| 名称 | 含义 | 选项值 |
|
||||
| :-: | :-: | :-: |
|
||||
| `--source` | 指定 `Docker CE` 源地址(域名或IP) | `地址` |
|
||||
| `--source-registry` | 指定 `Docker` 镜像仓库地址(域名或IP) | `地址` |
|
||||
| `--source-registry` | 指定 `Docker` 镜像仓库地址(域名或IP) | `地址(多个用英文逗号分割)` |
|
||||
| `--branch` | 指定 `Docker CE` 软件源仓库(路径) | `仓库名(详见下方文档)` |
|
||||
| `--branch-version` | 指定 `Docker CE` 软件源仓库版本 | `版本号(详见下方文档)` |
|
||||
| `--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 .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
|
||||
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) \
|
||||
--only-registry \
|
||||
--source-registry "docker.1ms.run,docker.1panel.live,docker.m.daocloud.io"
|
||||
```
|
||||
|
||||
=== "手动替换"
|
||||
|
||||
- 安装 `jq` 软件包
|
||||
|
||||
@@ -234,7 +234,7 @@ $ bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --zh-hant --help
|
||||
| 名稱 | 意義 | 選項值 |
|
||||
| :-: | :-: | :-: |
|
||||
| `--source` | 指定 `Docker CE` 軟體源位址(網域名稱或IP) | `位址` |
|
||||
| `--source-registry` | 指定 `Docker` 映像倉庫位址(網域名稱或IP) | `位址` |
|
||||
| `--source-registry` | 指定 `Docker` 映像倉庫位址(網域名稱或IP) | `位址(多個用英文逗號分割)` |
|
||||
| `--branch` | 指定 `Docker CE` 軟體源倉庫(路徑) | `倉庫名稱(詳見下方文件)` |
|
||||
| `--branch-version` | 指定 `Docker CE` 軟體源倉庫版本 | `版本號(詳見下方文件)` |
|
||||
| `--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 .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
|
||||
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` 軟體包
|
||||
|
||||
Reference in New Issue
Block a user