介紹#
docker-tar 是一個用於從 Docker 倉庫拉取鏡像並自動打包為 Tar 包的工具。
Github: docker-tar
特點#
- 無需 Docker 環境:二進制中包含了所有功能,開箱即用
- 多操作系統運行: 提供相關二進制,
Linux
、Windows
、MacOS
、Solaris
、OpenBSD
等操作系統均可使用,更多支持操作系統見 Release - 多處理器架構運行:提供相關二進制,支持
amd64/x64
、i386/x86
、arm
、arm64
、mips
、ppc64
等處理器架構,你可以使用 PC 甚至是路由器來運行此工具,更多支持架構見 Release - 鏡像模式下載:鏡像站點下載的鏡像 tar 無需進行 tag,可保持和輸入的鏡像名稱一致
- 登錄下載:支持需要認證的 Docker 倉庫及其鏡像站
- 選擇鏡像架構:支持選擇下載具有多架構的 Docker 鏡像
- 更接近 Docker CLI 的下載結果:此工具下載的 tar 鏡像文件,與使用
docker pull
和docker save
保存的文件完全一致 - 實驗室模式:提供解決 DNS 污染和 SNI 阻斷的實驗室模式,幫助你直連某些無法訪問的 Docker 倉庫站點
命令行使用說明#
-action action
pull: 拉取鏡像tar文件.
list: 列出可以拉取的處理器架構鏡像
-arch architecture
指定需要拉取的鏡像架構 (默認值為 "amd64")
-image name
需要下載的鏡像信息
不攜帶版本默認為latest
默認使用 DockerHub 的 Docker 倉庫
nginx
home-assistant/home-assistant:stable
ghcr.io/home-assistant/home-assistant:stable
-output filename
輸出 tar 鏡像的文件名,不指定此選項將隨機生成文件名
-username username
Docker 倉庫/鏡像站點需要登錄時,需要提供用戶名
-password password
Docker 倉庫/鏡像站點需要登錄時,需要提供密碼
-mirror string
使用鏡像站點下載鏡像
這種方式不會修改 -image 指定的名稱
-lab
實驗室模式,開啟將使用默認參數來規避 DNS 污染和 SNI 阻斷,pull和list模式下都可以使用。
一般情況下,默認設置是足夠的
-dns-servers ip list
實驗室模式開啟後,此選項生效。
工具內置了列表,輸入內容將覆蓋內置列表。
DNS伺服器配置選項,必須為解析後的 IP 地址,以逗號分割
-dns-timeout int
實驗室模式開啟後,此選項生效。
過濾DNS搶答的超時時間配置. (默認值 2s)
-network network
實驗室模式開啟後,此選項生效。
ip4: 僅使用 IPv4 下載鏡像
ip6: 僅使用 IPv6 下載鏡像
ip: 使用 IPv4以及IPv6 下載鏡像 (默認值 "ip")
使用示例#
列出目標鏡像支持的架構#
查詢 nginx 支持的架構
docker-tar -action list -image nginx
輸出結果
Available Architecture:
amd64
armv5
armv7
arm64v8
386
mips64le
ppc64le
s390x
下載鏡像(直接下載)#
使用這種方式需要配置 HTTPS_PROXY 環境變量
下載 nginx armv7 架構的 nginx
docker-tar -action pull -image nginx -arch armv7 -output nginx.tar
輸出結果
Pulling from nginx:latest
[1/7]3d83c6df5858: Downloading 100% |██████████████████████████████████████████████████| (24/24 MB, 1.9 MB/s)
[2/7]9260be83662e: Downloading 100% |██████████████████████████████████████████████████| (37/37 MB, 2.0 MB/s)
[3/7]3058d76256fc: Downloading 100% |██████████████████████████████████████████████████| (628/628 B, 986 kB/s)
[4/7]7888ef92f48d: Downloading 100% |██████████████████████████████████████████████████| (956/956 B, 994 kB/s)
[5/7]5c27d4148f08: Downloading 100% |██████████████████████████████████████████████████| (404/404 B, 400 kB/s)
[6/7]9c733a7e6553: Downloading 100% |█████████████████████████████████████████████████| (1.2/1.2 kB, 1.5 MB/s)
[7/7]931fb3c7333d: Downloading 100% |█████████████████████████████████████████████████| (1.4/1.4 kB, 2.5 MB/s)
Output File: nginx.tar
下載鏡像(通過鏡像站點)#
下載 nginx armv7 架構的 nginx
docker-tar -action pull -image nginx -arch armv7 -output nginx.tar -mirror docker.xuanyuan.me
輸出結果
Pulling from nginx:latest
[1/7]9c733a7e6553: Downloading 100% |█████████████████████████████████████████████████| (1.2/1.2 kB, 1.0 MB/s)
[2/7]931fb3c7333d: Downloading 100% |█████████████████████████████████████████████████| (1.4/1.4 kB, 2.8 MB/s)
[3/7]3d83c6df5858: Downloading 100% |███████████████████████████████████████████████████| (24/24 MB, 3.6 MB/s)
[4/7]9260be83662e: Downloading 100% |███████████████████████████████████████████████████| (37/37 MB, 5.2 MB/s)
[5/7]3058d76256fc: Downloading 100% |███████████████████████████████████████████████████| (628/628 B, 68 kB/s)
[6/7]7888ef92f48d: Downloading 100% |██████████████████████████████████████████████████| (956/956 B, 107 kB/s)
[7/7]5c27d4148f08: Downloading 100% |███████████████████████████████████████████████████| (404/404 B, 35 kB/s)
Output File: nginx.tar
下載鏡像(使用實驗室模式直接下載)#
下載 nginx armv7 架構的 nginx
docker-tar -action pull -image nginx -arch armv7 -output nginx.tar -lab
輸出結果
Pulling from nginx:latest
[1/7]3d83c6df5858: Downloading 100% |███████████████████████████████████████████████████| (24/24 MB, 6.9 MB/s)
[2/7]9260be83662e: Downloading 100% |████████████████████████████████████████████████████| (37/37 MB, 12 MB/s)
[3/7]3058d76256fc: Downloading 100% |██████████████████████████████████████████████████| (628/628 B, 489 kB/s)
[4/7]7888ef92f48d: Downloading 100% |██████████████████████████████████████████████████| (956/956 B, 671 kB/s)
[5/7]5c27d4148f08: Downloading 100% |██████████████████████████████████████████████████| (404/404 B, 353 kB/s)
[6/7]9c733a7e6553: Downloading 100% |█████████████████████████████████████████████████| (1.2/1.2 kB, 1.1 MB/s)
[7/7]931fb3c7333d: Downloading 100% |█████████████████████████████████████████████████| (1.4/1.4 kB, 2.8 MB/s)
Output File: nginx.tar
TODO#
- 多 Layer 並發下載
- 分片下載支持,對支持 Range 的響應實現分片下載
- Docker API 的兼容(ContentType)
- 代碼結構、命名調整
- 更友好的錯誤輸出
兼容情況(目前已測試)#
- DockerHub
- DockerHub 鏡像站
- ghcr.io
- ghcr.io 鏡像站
- quay.io (目前未適配 application/vnd.docker.distribution.manifest.v1+prettyjws)
- quay.io 鏡像站 (目前未適配 application/vnd.docker.distribution.manifest.v1+prettyjws)
一些可能有用的信息#
請求階段 | 支持的 ContentType | 其他 |
---|---|---|
獲取 Token | 只處理響應體,忽略類型 | Access Token, 用戶名密碼 (如需要): Basic |
獲取所有架構鏡像清單索引 | application/vnd.oci.image.index.v1+json | 響應非此類型會直接終止 |
獲取指定架構的鏡像清單 | application/vnd.oci.image.manifest.v1+json | 兼容類型也可 |
獲取鏡像配置 | application/vnd.oci.image.config.v1+json | 兼容類型也可 |
下載 Layer | application/vnd.oci.image.layer.v1.tar application/vnd.oci.image.layer.v1.tar+gzip application/vnd.oci.image.layer.v1.tar+zstd application/vnd.oci.image.layer.nondistributable.v1.tar application/vnd.oci.image.layer.nondistributable.v1.tar+gzip application/vnd.oci.image.layer.nondistributable.v1.tar+zstd application/vnd.docker.image.rootfs.diff.tar application/vnd.docker.image.rootfs.diff.tar.gzip application/vnd.docker.image.rootfs.diff.tar.zstd | 加密鏡像不支持 |