Error uploading image into Docker Registry using API v2

I am trying to upload Docker image (tarball) into private Docker registry using following API.
I am following the documentation here: http://docs.docker.com/registry/spec/api/

Step 1: Initiate the upload and get location URL

  • Docker MongoDB : UserNotFound
  • Docker image: virtual size vs real size
  • How to run bundle install with a Dockerfile file
  • How Can I Link a Apache and Tomcat Containers Over AJP?
  • How to have docker restart container with a completely new container?
  • Tomcat remote deploy with Intellj IDEA
  • $ 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
    

    Step 2: Use location URL to upload the actual Docker image

    $ 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
    

    Also, I am using sha256sum as follows:

    $ sha256sum /tmp/hello-world.tar                                             
    97bbb955c700a6414fd48ae147986e9b42c0508c8a766cea61e7e3badf0f7dde  /tmp/hello-world.tar 
    

    What I am possibly doing wrong here? How to get around DIGEST_INVALID error?

  • Command nesting in VSTS/TFS
  • Installing rancher 1.6.2 on centos 7
  • How to access a container from a Bluemix app?
  • Debug on Docker throws an error
  • deleting old images in Docker - OSX
  • How to manage Docker server by multi clients
  • One Solution collect form web for “Error uploading image into Docker Registry using API v2”

    Here is a simple example that should get you on track:

    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 will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.