一千萬個為什麽

搜索

從Docker Hub下載Docker鏡像,無需使用Docker



我想從 Docker Hub 手動下載Docker鏡像。更具體地說,我想在一臺沒有(也不能)安裝Docker客戶端軟件的受限環境中的機器上從Docker Hub下載Docker鏡像。我原以為這可以使用官方API ,但似乎並非如此 - 請參閱以下討論:

API是否真的不支持下載圖像?有沒有辦法解決這個問題?


更新1:

我遇到以下ServerFault文章:

接受的解決方案使用 docker save 命令,這對我的情況沒有幫助。但在那裏發布的另一個解決方案引用了以下StackOverflow帖子:

One of the solutions there refers to a command-line tool called docker-registry-debug which, among other things, can generate a curl command for downloading an image. Here is what I got:

[email protected]:~$ docker-registry-debug curlme docker ubuntu

# Reading user/passwd from env var "USER_CREDS"
# No password provided, disabling auth
# Getting token from https://index.docker.io
# Got registry endpoint from the server: https://registry-1.docker.io
# Got token: signature=1234567890abcde1234567890abcde1234567890,repository="library/docker",access=read
curl -i --location-trusted -I -X GET -H "Authorization: Token signature=1234567890abcde1234567890abcde1234567890,repository="library/docker",access=read" https://registry-1.docker.io/v1/images/ubuntu/layer

[email protected]:~$ curl \
-i --location-trusted -I -X GET \
-H "Authorization: Token signature=1234567890abcde1234567890abcde1234567890,repository="library/docker",access=read" 

https://registry-1.docker.io/v1/images/ubuntu/layer
HTTP/1.1 404 NOT FOUND
Server: gunicorn/18.0
Date: Wed, 29 Nov 2017 01:00:00 GMT
Expires: -1
Content-Type: application/json
Pragma: no-cache
Cache-Control: no-cache
Content-Length: 29
X-Docker-Registry-Version: 0.8.15
X-Docker-Registry-Config: common
Strict-Transport-Security: max-age=31536000

所以不幸的是,它看起來像生成的 curl 命令不起作用。


更新2:

它看起來像我能夠從Docker Hub下載圖層blob。這是我目前正在做的事情。

獲取授權令牌:

[email protected]:~$ export TOKEN=\
"$(curl \
--silent \
--header 'GET' \
"https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/ubuntu:pull" \
| jq -r '.token' \
)"

拉一個圖像清單:

[email protected]:~$ curl \
--silent \
--request 'GET' \
--header "Authorization: Bearer ${TOKEN}" \
'https://registry-1.docker.io/v2/library/ubuntu/manifests/latest' \
| jq '.'

拉一個圖像清單並提取blob和:

[email protected]:~$ curl \
--silent \
--request 'GET' \
--header "Authorization: Bearer ${TOKEN}" \
'https://registry-1.docker.io/v2/library/ubuntu/manifests/latest' \
| jq -r '.fsLayers[].blobSum'

sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
sha256:be588e74bd348ce48bb7161350f4b9d783c331f37a853a80b0b4abc0a33c569e
sha256:e4ce6c3651b3a090bb43688f512f687ea6e3e533132bcbc4a83fb97e7046cea3
sha256:421e436b5f80d876128b74139531693be9b4e59e4f1081c9a3c379c95094e375
sha256:4c7380416e7816a5ab1f840482c9c3ca8de58c6f3ee7f95e55ad299abbfe599f
sha256:660c48dd555dcbfdfe19c80a30f557ac57a15f595250e67bfad1e5663c1725bb

下載單層blob並將其寫入文件:

[email protected]:~$ BLOBSUM=\
"sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4"

[email protected]:~$ curl \
--silent \
--location \
--request GET \
--header "Authorization: Bearer ${TOKEN}" \
"https://registry-1.docker.io/v2/library/ubuntu/blobs/${BLOBSUM}" \
> "${BLOBSUM/*:/}.gz"

將所有blob和寫入文件:

[email protected]:~$ curl \
--silent \
--request 'GET' \
--header "Authorization: Bearer ${TOKEN}" \
'https://registry-1.docker.io/v2/library/ubuntu/manifests/latest' \
| jq -r '.fsLayers[].blobSum' > ubuntu-blobsums.txt

從清單中下載所有層blob:

[email protected]:~$ while read BLOBSUM; do
curl \
--silent \
--location \
--request 'GET' \
--header "Authorization: Bearer ${TOKEN}" \
"https://registry-1.docker.io/v2/library/ubuntu/blobs/${BLOBSUM}" \
> "${BLOBSUM/*:/}.gz"; \
done < blobsums.txt

現在我有一堆圖層斑點,我需要將它們重新組合成一幅圖像 - 我想。


相關鏈接:

轉載註明原文: 從Docker Hub下載Docker鏡像,無需使用Docker

一共有 2 個回答:

所以事實證明, Moby Project Moby Github ,它可以從 Docker Hub 格式,可以導入到Docker中:

該腳本的使用語法如下所示:

download-frozen-image-v2.sh target_dir image[:tag][@digest] ...

然後可以使用 tardocker load 導入該圖像:

tar -cC 'target_dir' . | docker load

為了驗證腳本是否按預期運行,我從Docker Hub下載了一個Ubuntu鏡像並將其加載到Docker中:

[email protected]:~$ bash download-frozen-image-v2.sh ubuntu ubuntu:latest
[email protected]:~$ tar -cC 'ubuntu' . | docker load
[email protected]:~$ docker run --rm -ti ubuntu bash
[email protected]:/#

在實踐中,我必須首先將數據從互聯網客戶端(沒有安裝Docker)復制到目標/目標機器(安裝Docker的 ):

[email protected]:~$ bash download-frozen-image-v2.sh ubuntu ubuntu:latest
[email protected]:~$ tar -C 'ubuntu' -cf 'ubuntu.tar' .
[email protected]:~$ scp ubuntu.tar [email protected]:~

然後加載並使用目標主機上的映像:

[email protected]:~ docker load ubuntu.tar
[email protected]:~ docker run --rm -ti ubuntu bash
[email protected]:/#

To me it is not completely clear what you are trying to achieve and why the attempts are not a solution for the problem. If I would need to solve this issue I would like @Tensibai and other Q&As indicated, do a docker pull first on a system with internet connectivity, save the docker image, copy it to the machine without internet connectivity, load the image and run it.

示範</強>

系統A上沒有圖像:

[email protected] ~ $ docker images
REPOSITORY        TAG               IMAGE ID          CREATED             SIZE
[email protected] ~ $

從dockerhub中拉出圖片:

[email protected] ~ $
docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
bc95e04b23c0: Pull complete 
f3186e650f4e: Pull complete 
9ac7d6621708: Pull complete 
Digest: sha256:b81f317384d7388708a498555c28a7cce778a8f291d90021208b3eba3fe74887
Status: Downloaded newer image for nginx:latest
[email protected] ~ $ docker images
REPOSITORY        TAG               IMAGE ID            CREATED             SIZE
nginx             latest            9e7424e5dbae        10 days ago         108MB

保存碼頭圖像:

[email protected] ~ $ docker save nginx -o nginx.tar

將docker映像復制到systemB並加載它。

[email protected] ~ $ docker load -i nginx.tar
cec7521cdf36: Loading layer  58.44MB/58.44MB
350d50e58b6c: Loading layer  53.76MB/53.76MB
63c39cd4a775: Loading layer  3.584kB/3.584kB
Loaded image: nginx:latest
[email protected] ~ $ docker images
REPOSITORY        TAG               IMAGE ID            CREATED             SIZE
nginx             latest            9e7424e5dbae        10 days ago         108MB