gpt4 book ai didi

docker - 使用 API v2 将图像上传到 Docker Registry 时出错

转载 作者:行者123 更新时间:2023-12-02 19:42:11 26 4
gpt4 key购买 nike

我正在尝试使用以下 API 将 Docker 镜像(tarball)上传到私有(private) Docker 注册表。
我在这里关注文档:http://docs.docker.com/registry/spec/api/

第 1 步:启动上传并获取位置 URL

$ curl -v -X POST http://localhost:5000/v2/hello-world/blobs/uploads/        * About to connect() to localhost port 5000 (#0)
* Trying ::1...
* Connected to localhost (::1) port 5000 (#0)
> POST /v2/hello-world/blobs/uploads/ HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:5000
> Accept: */*
>
< HTTP/1.1 202 Accepted
< Content-Length: 0
< Docker-Distribution-Api-Version: registry/2.0
< Docker-Upload-Uuid: dd319793-f017-45b3-afe4-c8102363a8df
< Location: http://localhost:5000/v2/hello-world/blobs/uploads/dd319793-f017-45b3-afe4-c8102363a8df?_state=SB2605fFM_7KNkYTHjVrVQVT62dufwXNTw9QzO2_aRR7Ik5hbWUiOiJoZWxsby13b3JsZCIsIlVVSUQiOiJkZDMxOTc5My1mMDE3LTQ1YjMtYWZlNC1jODEwMjM2M2E4ZGYiLCJPZmZzZXQiOjAsIlN0YXJ0ZWRBdCI6IjIwMTUtMTAtMjdUMjI6MjU6MjEuMTM0MTI5MDNaIn0%3D
< Range: 0-0
< Date: Tue, 27 Oct 2015 22:25:21 GMT
< Content-Type: text/plain; charset=utf-8
<
* Connection #0 to host localhost left intact

步骤 2:使用位置 URL 上传实际的 Docker 镜像
$ curl -v -H "Content-type: application/octet-stream" -H "Content-Length: 13824" --data-binary @/tmp/hello-world.tar -X PUT -L "http://localhost:5000/v2/hello-world/blobs/uploads/dd319793-f017-45b3-afe4-c8102363a8df?_state=SB2605fFM_7KNkYTHjVrVQVT62dufwXNTw9QzO2_aRR7Ik5hbWUiOiJoZWxsby13b3JsZCIsIlVVSUQiOiJkZDMxOTc5My1mMDE3LTQ1YjMtYWZlNC1jODEwMjM2M2E4ZGYiLCJPZmZzZXQiOjAsIlN0YXJ0ZWRBdCI6IjIwMTUtMTAtMjdUMjI6MjU6MjEuMTM0MTI5MDNaIn0%3D&digest=tarsum.v2+sha256:97bbb955c700a6414fd48ae147986e9b42c0508c8a766cea61e7e3badf0f7dde"
* About to connect() to localhost port 5000 (#0)
* Trying ::1...
* Connected to localhost (::1) port 5000 (#0)
> PUT /v2/hello-world/blobs/uploads/dd319793-f017-45b3-afe4-c8102363a8df?_state=SB2605fFM_7KNkYTHjVrVQVT62dufwXNTw9QzO2_aRR7Ik5hbWUiOiJoZWxsby13b3JsZCIsIlVVSUQiOiJkZDMxOTc5My1mMDE3LTQ1YjMtYWZlNC1jODEwMjM2M2E4ZGYiLCJPZmZzZXQiOjAsIlN0YXJ0ZWRBdCI6IjIwMTUtMTAtMjdUMjI6MjU6MjEuMTM0MTI5MDNaIn0%3D&digest=tarsum.v2+sha256:97bbb955c700a6414fd48ae147986e9b42c0508c8a766cea61e7e3badf0f7dde HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:5000
> Accept: */*
> Content-type: application/octet-stream
> Content-Length: 13824
> Expect: 100-continue
>
* Done waiting for 100-continue
< HTTP/1.1 400 Bad Request
< Content-Type: application/json; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
< Date: Tue, 27 Oct 2015 22:29:02 GMT
< Content-Length: 131
* HTTP error before end of send, stop sending
<
{"errors":[{"code":"DIGEST_INVALID","message":"provided digest did not match uploaded content","detail":"digest parsing failed"}]}
* Closing connection 0

另外,我使用 sha256sum 如下:
$ sha256sum /tmp/hello-world.tar                                             
97bbb955c700a6414fd48ae147986e9b42c0508c8a766cea61e7e3badf0f7dde /tmp/hello-world.tar

我在这里可能做错了什么?如何解决 DIGEST_INVALID 错误?

最佳答案

这是一个简单的示例,可以让您走上正轨:

local reponame=foo/bar
local uploadURL
local numBytes=10000000 # 10 Megabytes

uploadURL=$(curl -siL -X POST "https://registrydomain/v2/$reponame/blobs/uploads/" | grep 'Location:' | cut -d ' ' -f 2 | tr -d '[:space:]')

blobDigest="sha256:$(head -c $numBytes /dev/urandom | tee upload.tmp | shasum -a 256 | cut -d ' ' -f 1)"

echo "Uploading Blob of 10 Random Megabytes"
time curl -T upload.tmp --progress-bar "$uploadURL&digest=$blobDigest" > /dev/null

关于docker - 使用 API v2 将图像上传到 Docker Registry 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33380605/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com