docker-archive / migrator

Tool to migrate Docker images from Docker Hub or v1 registry to a v2 registry
Apache License 2.0
160 stars 82 forks source link

V2 registry check - Only check the HTTP response status #63

Closed jeanblanchard closed 8 years ago

jeanblanchard commented 8 years ago

The API documentation does not specify the response body for the version check request, so do not make assumptions about it.

In my current tests, it actually returns an empty object, which fails the check.

mbentley commented 8 years ago

You're correct about the response body but what we are actually checking is the header as we are using the -I option w/curl. From the API documentation it does stipulate: "When a 200 OK or 401 Unauthorized response is returned, the “Docker-Distribution-API-Version” header should be set to “registry/2.0”. Clients may require this header value to determine if the endpoint serves this API. When this header is omitted, clients may fallback to an older API version."

So in this case, we are acting as a client to check to see if the endpoint serves the registry 2 API. Per the documentation for the registry: "Getting the headers correct is very important. For all responses to any request under the “/v2/” url space, the Docker-Distribution-API-Version header should be set to the value “registry/2.0”, even for a 4xx response. This header allows the docker engine to quickly resolve authentication realms and fallback to version 1 registries, if necessary. Confirming this is setup correctly can help avoid problems with fallback."

jeanblanchard commented 8 years ago

You're right, the header is indeed returned on my server, so it should have worked. I'll have to check tomorrow to find out the real reason why it didn't .

jeanblanchard commented 8 years ago

Okay, so after adding a few logs, it turns out my issue was that I wanted http for the V1 registry, but https for the V2 registry, so I was actually getting a 404 from the V1 registry when checking for the V2 version.

I'm closing this, and I'll create a new PR to handle this case.