heroku / docker-registry-client

A Go API client for the v2 Docker Registry API
BSD 3-Clause "New" or "Revised" License
297 stars 225 forks source link

i remove image, use hub.ManifestDigest("nginx", "1.14.1"),but in the manifest.go ManifestDigest() resp == nil #65

Open ap6108 opened 5 years ago

ap6108 commented 5 years ago

i remove image, use hub.ManifestDigest("nginx", "1.14.1"), but in the manifest.go ManifestDigest() resp == nil. sameple is : digest, err2 := hub.ManifestDigest(requestObject.Name, requestObject.Version) in the menifest.go :+1: resp, err := registry.Client.Head(url) fmt.Printf("resp %+v\n", resp)

the resp is nil how to do it? thanks!

kispaljr commented 5 years ago

Hi!

Well, the name of the nginx repository should be library/nginx. Otherwise this works for me:

package main

import (
    "fmt"

    "github.com/heroku/docker-registry-client/registry"
)

func main() {
    url := "https://registry-1.docker.io/"
    username := "" // anonymous
    password := "" // anonymous
    hub, err := registry.New(url, username, password)

    digest, err := hub.ManifestDigest("library/nginx", "1.14.1")
    fmt.Print(digest, err)
}

Please note however that the return value will be the hash of the schema1 manifest. For the schema2 manifest you should use something like the method added in @peragwin's PR: https://github.com/heroku/docker-registry-client/pull/51

ap6108 commented 5 years ago

in v2,docker 17.03, it is also get nil resp. the error is: ManifestDigest: Head http://192.168.2.39:8082/v2/httpd/manifests/2.4.37: http: non-successful response (status=404 body="")

func (registry *Registry) ManifestV2Digest(repository, reference string) (digest.Digest, error) { url := registry.url("/v2/%s/manifests/%s", repository, reference) registry.Logf("registry.manifest.head url=%s repository=%s reference=%s", url, repository, reference) req, err := http.NewRequest("HEAD", url, nil) if err != nil { return "", err } req.Header.Set("Accept", schema2.MediaTypeManifest) resp, err := registry.Client.Do(req) if resp != nil { defer resp.Body.Close() } if err != nil { return "", err } return digest.Parse(resp.Header.Get("Docker-Content-Digest")) } but it fail.

if i do this: curl -u admin:admin123 --head -XGET -H "Accept: application/vnd.docker.distribution.manifest.v2+json" http://192.168.2.39:8082/v2/httpd/manifests/2.4.37 it is ok.

and how do solved it?

ap6108 commented 5 years ago

i solved it. the fuc ManifestV2Digest() modify "HEAD" to "GET"