github.com/npaton/distribution@v2.3.1-rc.0+incompatible/docs/spec/api.md.tmpl (about)

     1  <!--[metadata]>
     2  +++
     3  title = "HTTP API V2"
     4  description = "Specification for the Registry API."
     5  keywords = ["registry, on-prem, images, tags, repository, distribution, api, advanced"]
     6  [menu.main]
     7  parent="smn_registry_ref"
     8  +++
     9  <![end-metadata]-->
    10  
    11  # Docker Registry HTTP API V2
    12  
    13  ## Introduction
    14  
    15  The _Docker Registry HTTP API_ is the protocol to facilitate distribution of
    16  images to the docker engine. It interacts with instances of the docker
    17  registry, which is a service to manage information about docker images and
    18  enable their distribution. The specification covers the operation of version 2
    19  of this API, known as _Docker Registry HTTP API V2_.
    20  
    21  While the V1 registry protocol is usable, there are several problems with the
    22  architecture that have led to this new version. The main driver of this
    23  specification these changes to the docker the image format, covered in
    24  [docker/docker#8093](https://github.com/docker/docker/issues/8093). The new, self-contained image manifest simplifies image
    25  definition and improves security. This specification will build on that work,
    26  leveraging new properties of the manifest format to improve performance,
    27  reduce bandwidth usage and decrease the likelihood of backend corruption.
    28  
    29  For relevant details and history leading up to this specification, please see
    30  the following issues:
    31  
    32  - [docker/docker#8093](https://github.com/docker/docker/issues/8093)
    33  - [docker/docker#9015](https://github.com/docker/docker/issues/9015)
    34  - [docker/docker-registry#612](https://github.com/docker/docker-registry/issues/612)
    35  
    36  ### Scope
    37  
    38  This specification covers the URL layout and protocols of the interaction
    39  between docker registry and docker core. This will affect the docker core
    40  registry API and the rewrite of docker-registry. Docker registry
    41  implementations may implement other API endpoints, but they are not covered by
    42  this specification.
    43  
    44  This includes the following features:
    45  
    46  - Namespace-oriented URI Layout
    47  - PUSH/PULL registry server for V2 image manifest format
    48  - Resumable layer PUSH support
    49  - V2 Client library implementation
    50  
    51  While authentication and authorization support will influence this
    52  specification, details of the protocol will be left to a future specification.
    53  Relevant header definitions and error codes are present to provide an
    54  indication of what a client may encounter.
    55  
    56  #### Future
    57  
    58  There are features that have been discussed during the process of cutting this
    59  specification. The following is an incomplete list:
    60  
    61  - Immutable image references
    62  - Multiple architecture support
    63  - Migration from v2compatibility representation
    64  
    65  These may represent features that are either out of the scope of this
    66  specification, the purview of another specification or have been deferred to a
    67  future version.
    68  
    69  ### Use Cases
    70  
    71  For the most part, the use cases of the former registry API apply to the new
    72  version. Differentiating use cases are covered below.
    73  
    74  #### Image Verification
    75  
    76  A docker engine instance would like to run verified image named
    77  "library/ubuntu", with the tag "latest". The engine contacts the registry,
    78  requesting the manifest for "library/ubuntu:latest". An untrusted registry
    79  returns a manifest. Before proceeding to download the individual layers, the
    80  engine verifies the manifest's signature, ensuring that the content was
    81  produced from a trusted source and no tampering has occured. After each layer
    82  is downloaded, the engine verifies the digest of the layer, ensuring that the
    83  content matches that specified by the manifest.
    84  
    85  #### Resumable Push
    86  
    87  Company X's build servers lose connectivity to docker registry before
    88  completing an image layer transfer. After connectivity returns, the build
    89  server attempts to re-upload the image. The registry notifies the build server
    90  that the upload has already been partially attempted. The build server
    91  responds by only sending the remaining data to complete the image file.
    92  
    93  #### Resumable Pull
    94  
    95  Company X is having more connectivity problems but this time in their
    96  deployment datacenter. When downloading an image, the connection is
    97  interrupted before completion. The client keeps the partial data and uses http
    98  `Range` requests to avoid downloading repeated data.
    99  
   100  #### Layer Upload De-duplication
   101  
   102  Company Y's build system creates two identical docker layers from build
   103  processes A and B. Build process A completes uploading the layer before B.
   104  When process B attempts to upload the layer, the registry indicates that its
   105  not necessary because the layer is already known.
   106  
   107  If process A and B upload the same layer at the same time, both operations
   108  will proceed and the first to complete will be stored in the registry (Note:
   109  we may modify this to prevent dogpile with some locking mechanism).
   110  
   111  ### Changes
   112  
   113  The V2 specification has been written to work as a living document, specifying
   114  only what is certain and leaving what is not specified open or to future
   115  changes. Only non-conflicting additions should be made to the API and accepted
   116  changes should avoid preventing future changes from happening.
   117  
   118  This section should be updated when changes are made to the specification,
   119  indicating what is different. Optionally, we may start marking parts of the
   120  specification to correspond with the versions enumerated here.
   121  
   122  Each set of changes is given a letter corresponding to a set of modifications
   123  that were applied to the baseline specification. These are merely for
   124  reference and shouldn't be used outside the specification other than to
   125  identify a set of modifications.
   126  
   127  <dl>
   128    <dt>j</dt>
   129    <dd>
   130      <ul>
   131        <li>Add ability to mount blobs across repositories.</li>
   132      </ul>
   133    </dd>
   134  
   135    <dt>i</dt>
   136    <dd>
   137      <ul>
   138        <li>Clarified expected behavior response to manifest HEAD request.</li>
   139      </ul>
   140    </dd>
   141  
   142    <dt>h</dt>
   143    <dd>
   144      <ul>
   145        <li>All mention of tarsum removed.</li>
   146      </ul>
   147    </dd>
   148  
   149    <dt>g</dt>
   150    <dd>
   151      <ul>
   152        <li>Clarify behavior of pagination behavior with unspecified parameters.</li>
   153      </ul>
   154    </dd>
   155  
   156    <dt>f</dt>
   157    <dd>
   158      <ul>
   159        <li>Specify the delete API for layers and manifests.</li>
   160      </ul>
   161    </dd>
   162  
   163    <dt>e</dt>
   164    <dd>
   165      <ul>
   166        <li>Added support for listing registry contents.</li>
   167        <li>Added pagination to tags API.</li>
   168        <li>Added common approach to support pagination.</li>
   169      </ul>
   170    </dd>
   171  
   172    <dt>d</dt>
   173    <dd>
   174      <ul>
   175        <li>Allow repository name components to be one character.</li>
   176        <li>Clarified that single component names are allowed.</li>
   177      </ul>
   178    </dd>
   179  
   180    <dt>c</dt>
   181    <dd>
   182      <ul>
   183        <li>Added section covering digest format.</li>
   184        <li>Added more clarification that manifest cannot be deleted by tag.</li>
   185      </ul>
   186    </dd>
   187  
   188    <dt>b</dt>
   189    <dd>
   190      <ul>
   191        <li>Added capability of doing streaming upload to PATCH blob upload.</li>
   192        <li>Updated PUT blob upload to no longer take final chunk, now requires entire data or no data.</li>
   193        <li>Removed `416 Requested Range Not Satisfiable` response status from PUT blob upload.</li>
   194      </ul>
   195    </dd>
   196  
   197    <dt>a</dt>
   198    <dd>
   199      <ul>
   200        <li>Added support for immutable manifest references in manifest endpoints.</li>
   201        <li>Deleting a manifest by tag has been deprecated.</li>
   202        <li>Specified `Docker-Content-Digest` header for appropriate entities.</li>
   203        <li>Added error code for unsupported operations.</li>
   204      </ul>
   205    </dd>
   206  </dl>
   207  
   208  ## Overview
   209  
   210  This section covers client flows and details of the API endpoints. The URI
   211  layout of the new API is structured to support a rich authentication and
   212  authorization model by leveraging namespaces. All endpoints will be prefixed
   213  by the API version and the repository name:
   214  
   215      /v2/<name>/
   216  
   217  For example, an API endpoint that will work with the `library/ubuntu`
   218  repository, the URI prefix will be:
   219  
   220      /v2/library/ubuntu/
   221  
   222  This scheme provides rich access control over various operations and methods
   223  using the URI prefix and http methods that can be controlled in variety of
   224  ways.
   225  
   226  Classically, repository names have always been two path components where each
   227  path component is less than 30 characters. The V2 registry API does not
   228  enforce this. The rules for a repository name are as follows:
   229  
   230  1. A repository name is broken up into _path components_. A component of a
   231     repository name must be at least one lowercase, alpha-numeric characters,
   232     optionally separated by periods, dashes or underscores. More strictly, it
   233     must match the regular expression `[a-z0-9]+(?:[._-][a-z0-9]+)*`.
   234  2. If a repository  name has two or more path components, they must be
   235     separated by a forward slash ("/").
   236  3. The total length of a repository name, including slashes, must be less the
   237     256 characters.
   238  
   239  These name requirements _only_ apply to the registry API and should accept a
   240  superset of what is supported by other docker ecosystem components.
   241  
   242  All endpoints should support aggressive http caching, compression and range
   243  headers, where appropriate. The new API attempts to leverage HTTP semantics
   244  where possible but may break from standards to implement targeted features.
   245  
   246  For detail on individual endpoints, please see the [_Detail_](#detail)
   247  section.
   248  
   249  ### Errors
   250  
   251  Actionable failure conditions, covered in detail in their relevant sections,
   252  are reported as part of 4xx responses, in a json response body. One or more
   253  errors will be returned in the following format:
   254  
   255      {
   256          "errors:" [{
   257                  "code": <error identifier>,
   258                  "message": <message describing condition>,
   259                  "detail": <unstructured>
   260              },
   261              ...
   262          ]
   263      }
   264  
   265  The `code` field will be a unique identifier, all caps with underscores by
   266  convention. The `message` field will be a human readable string. The optional
   267  `detail` field may contain arbitrary json data providing information the
   268  client can use to resolve the issue.
   269  
   270  While the client can take action on certain error codes, the registry may add
   271  new error codes over time. All client implementations should treat unknown
   272  error codes as `UNKNOWN`, allowing future error codes to be added without
   273  breaking API compatibility. For the purposes of the specification error codes
   274  will only be added and never removed.
   275  
   276  For a complete account of all error codes, please see the _Detail_ section.
   277  
   278  ### API Version Check
   279  
   280  A minimal endpoint, mounted at `/v2/` will provide version support information
   281  based on its response statuses. The request format is as follows:
   282  
   283      GET /v2/
   284  
   285  If a `200 OK` response is returned, the registry implements the V2(.1)
   286  registry API and the client may proceed safely with other V2 operations.
   287  Optionally, the response may contain information about the supported paths in
   288  the response body. The client should be prepared to ignore this data.
   289  
   290  If a `401 Unauthorized` response is returned, the client should take action
   291  based on the contents of the "WWW-Authenticate" header and try the endpoint
   292  again. Depending on access control setup, the client may still have to
   293  authenticate against different resources, even if this check succeeds.
   294  
   295  If `404 Not Found` response status, or other unexpected status, is returned,
   296  the client should proceed with the assumption that the registry does not
   297  implement V2 of the API.
   298  
   299  When a `200 OK` or `401 Unauthorized` response is returned, the
   300  "Docker-Distribution-API-Version" header should be set to "registry/2.0".
   301  Clients may require this header value to determine if the endpoint serves this
   302  API. When this header is omitted, clients may fallback to an older API version.
   303  
   304  ### Content Digests
   305  
   306  This API design is driven heavily by [content addressability](http://en.wikipedia.org/wiki/Content-addressable_storage).
   307  The core of this design is the concept of a content addressable identifier. It
   308  uniquely identifies content by taking a collision-resistant hash of the bytes.
   309  Such an identifier can be independently calculated and verified by selection
   310  of a common _algorithm_. If such an identifier can be communicated in a secure
   311  manner, one can retrieve the content from an insecure source, calculate it
   312  independently and be certain that the correct content was obtained. Put simply,
   313  the identifier is a property of the content.
   314  
   315  To disambiguate from other concepts, we call this identifier a _digest_. A
   316  _digest_ is a serialized hash result, consisting of a _algorithm_ and _hex_
   317  portion. The _algorithm_ identifies the methodology used to calculate the
   318  digest. The _hex_ portion is the hex-encoded result of the hash.
   319  
   320  We define a _digest_ string to match the following grammar:
   321  ```
   322  digest      := algorithm ":" hex
   323  algorithm   := /[A-Fa-f0-9_+.-]+/
   324  hex         := /[A-Fa-f0-9]+/
   325  ```
   326  
   327  Some examples of _digests_ include the following:
   328  
   329  digest                                                                            | description                                   |
   330  ----------------------------------------------------------------------------------|------------------------------------------------
   331  sha256:6c3c624b58dbbcd3c0dd82b4c53f04194d1247c6eebdaab7c610cf7d66709b3b           | Common sha256 based digest                    |
   332  
   333  While the _algorithm_ does allow one to implement a wide variety of
   334  algorithms, compliant implementations should use sha256. Heavy processing of
   335  input before calculating a hash is discouraged to avoid degrading the
   336  uniqueness of the _digest_ but some canonicalization may be performed to
   337  ensure consistent identifiers.
   338  
   339  Let's use a simple example in pseudo-code to demonstrate a digest calculation:
   340  ```
   341  let C = 'a small string'
   342  let B = sha256(C)
   343  let D = 'sha256:' + EncodeHex(B)
   344  let ID(C) = D
   345  ```
   346  
   347  Above, we have bytestring `C` passed into a function, `SHA256`, that returns a
   348  bytestring `B`, which is the hash of `C`. `D` gets the algorithm concatenated
   349  with the hex encoding of `B`. We then define the identifier of `C` to `ID(C)`
   350  as equal to `D`. A digest can be verified by independently calculating `D` and
   351  comparing it with identifier `ID(C)`.
   352  
   353  #### Digest Header
   354  
   355  To provide verification of http content, any response may include a `Docker-
   356  Content-Digest` header. This will include the digest of the target entity
   357  returned in the response. For blobs, this is the entire blob content. For
   358  manifests, this is the manifest body without the signature content, also known
   359  as the JWS payload. Note that the commonly used canonicalization for digest
   360  calculation may be dependent on the mediatype of the content, such as with
   361  manifests.
   362  
   363  The client may choose to ignore the header or may verify it to ensure content
   364  integrity and transport security. This is most important when fetching by a
   365  digest. To ensure security, the content should be verified against the digest
   366  used to fetch the content. At times, the returned digest may differ from that
   367  used to initiate a request. Such digests are considered to be from different
   368  _domains_, meaning they have different values for _algorithm_. In such a case,
   369  the client may choose to verify the digests in both domains or ignore the
   370  server's digest. To maintain security, the client _must_ always verify the
   371  content against the _digest_ used to fetch the content.
   372  
   373  > __IMPORTANT:__ If a _digest_ is used to fetch content, the client should use
   374  > the same digest used to fetch the content to verify it. The header `Docker-
   375  > Content-Digest` should not be trusted over the "local" digest.
   376  
   377  ### Pulling An Image
   378  
   379  An "image" is a combination of a JSON manifest and individual layer files. The
   380  process of pulling an image centers around retrieving these two components.
   381  
   382  The first step in pulling an image is to retrieve the manifest. For reference,
   383  the relevant manifest fields for the registry are the following:
   384  
   385   field    | description                                    |
   386  ----------|------------------------------------------------|
   387  name      | The name of the image.                         |
   388  tag       | The tag for this version of the image.         |
   389  fsLayers  | A list of layer descriptors (including digest) |
   390  signature | A JWS used to verify the manifest content      |
   391  
   392  For more information about the manifest format, please see
   393  [docker/docker#8093](https://github.com/docker/docker/issues/8093).
   394  
   395  When the manifest is in hand, the client must verify the signature to ensure
   396  the names and layers are valid. Once confirmed, the client will then use the
   397  digests to download the individual layers. Layers are stored in as blobs in
   398  the V2 registry API, keyed by their digest.
   399  
   400  #### Pulling an Image Manifest
   401  
   402  The image manifest can be fetched with the following url:
   403  
   404  ```
   405  GET /v2/<name>/manifests/<reference>
   406  ```
   407  
   408  The `name` and `reference` parameter identify the image and are required. The
   409  reference may include a tag or digest.
   410  
   411  A `404 Not Found` response will be returned if the image is unknown to the
   412  registry. If the image exists and the response is successful, the image
   413  manifest will be returned, with the following format (see docker/docker#8093
   414  for details):
   415  
   416      {
   417         "name": <name>,
   418         "tag": <tag>,
   419         "fsLayers": [
   420            {
   421               "blobSum": <digest>
   422            },
   423            ...
   424          ]
   425         ],
   426         "history": <v1 images>,
   427         "signature": <JWS>
   428      }
   429  
   430  The client should verify the returned manifest signature for authenticity
   431  before fetching layers.
   432  
   433  ##### Existing Manifests
   434  
   435  The image manifest can be checked for existence with the following url:
   436  
   437  ```
   438  HEAD /v2/<name>/manifests/<reference>
   439  ```
   440  
   441  The `name` and `reference` parameter identify the image and are required. The
   442  reference may include a tag or digest.
   443  
   444  A `404 Not Found` response will be returned if the image is unknown to the
   445  registry. If the image exists and the response is successful the response will
   446  be as follows:
   447  
   448  ```
   449  200 OK
   450  Content-Length: <length of manifest>
   451  Docker-Content-Digest: <digest>
   452  ```
   453  
   454  
   455  #### Pulling a Layer
   456  
   457  Layers are stored in the blob portion of the registry, keyed by digest.
   458  Pulling a layer is carried out by a standard http request. The URL is as
   459  follows:
   460  
   461      GET /v2/<name>/blobs/<digest>
   462  
   463  Access to a layer will be gated by the `name` of the repository but is
   464  identified uniquely in the registry by `digest`.
   465  
   466  This endpoint may issue a 307 (302 for <HTTP 1.1) redirect to another service
   467  for downloading the layer and clients should be prepared to handle redirects.
   468  
   469  This endpoint should support aggressive HTTP caching for image layers. Support
   470  for Etags, modification dates and other cache control headers should be
   471  included. To allow for incremental downloads, `Range` requests should be
   472  supported, as well.
   473  
   474  ### Pushing An Image
   475  
   476  Pushing an image works in the opposite order as a pull. After assembling the
   477  image manifest, the client must first push the individual layers. When the
   478  layers are fully pushed into the registry, the client should upload the signed
   479  manifest.
   480  
   481  The details of each step of the process are covered in the following sections.
   482  
   483  #### Pushing a Layer
   484  
   485  All layer uploads use two steps to manage the upload process. The first step
   486  starts the upload in the registry service, returning a url to carry out the
   487  second step. The second step uses the upload url to transfer the actual data.
   488  Uploads are started with a POST request which returns a url that can be used
   489  to push data and check upload status.
   490  
   491  The `Location` header will be used to communicate the upload location after
   492  each request. While it won't change in the this specification, clients should
   493  use the most recent value returned by the API.
   494  
   495  ##### Starting An Upload
   496  
   497  To begin the process, a POST request should be issued in the following format:
   498  
   499  ```
   500  POST /v2/<name>/blobs/uploads/
   501  ```
   502  
   503  The parameters of this request are the image namespace under which the layer
   504  will be linked. Responses to this request are covered below.
   505  
   506  ##### Existing Layers
   507  
   508  The existence of a layer can be checked via a `HEAD` request to the blob store
   509  API. The request should be formatted as follows:
   510  
   511  ```
   512  HEAD /v2/<name>/blobs/<digest>
   513  ```
   514  
   515  If the layer with the digest specified in `digest` is available, a 200 OK
   516  response will be received, with no actual body content (this is according to
   517  http specification). The response will look as follows:
   518  
   519  ```
   520  200 OK
   521  Content-Length: <length of blob>
   522  Docker-Content-Digest: <digest>
   523  ```
   524  
   525  When this response is received, the client can assume that the layer is
   526  already available in the registry under the given name and should take no
   527  further action to upload the layer. Note that the binary digests may differ
   528  for the existing registry layer, but the digests will be guaranteed to match.
   529  
   530  ##### Uploading the Layer
   531  
   532  If the POST request is successful, a `202 Accepted` response will be returned
   533  with the upload URL in the `Location` header:
   534  
   535  ```
   536  202 Accepted
   537  Location: /v2/<name>/blobs/uploads/<uuid>
   538  Range: bytes=0-<offset>
   539  Content-Length: 0
   540  Docker-Upload-UUID: <uuid>
   541  ```
   542  
   543  The rest of the upload process can be carried out with the returned url,
   544  called the "Upload URL" from the `Location` header. All responses to the
   545  upload url, whether sending data or getting status, will be in this format.
   546  Though the URI format (`/v2/<name>/blobs/uploads/<uuid>`) for the `Location`
   547  header is specified, clients should treat it as an opaque url and should never
   548  try to assemble the it. While the `uuid` parameter may be an actual UUID, this
   549  proposal imposes no constraints on the format and clients should never impose
   550  any.
   551  
   552  If clients need to correlate local upload state with remote upload state, the
   553  contents of the `Docker-Upload-UUID` header should be used. Such an id can be
   554  used to key the last used location header when implementing resumable uploads.
   555  
   556  ##### Upload Progress
   557  
   558  The progress and chunk coordination of the upload process will be coordinated
   559  through the `Range` header. While this is a non-standard use of the `Range`
   560  header, there are examples of [similar approaches](https://developers.google.com/youtube/v3/guides/using_resumable_upload_protocol) in APIs with heavy use.
   561  For an upload that just started, for an example with a 1000 byte layer file,
   562  the `Range` header would be as follows:
   563  
   564  ```
   565  Range: bytes=0-0
   566  ```
   567  
   568  To get the status of an upload, issue a GET request to the upload URL:
   569  
   570  ```
   571  GET /v2/<name>/blobs/uploads/<uuid>
   572  Host: <registry host>
   573  ```
   574  
   575  The response will be similar to the above, except will return 204 status:
   576  
   577  ```
   578  204 No Content
   579  Location: /v2/<name>/blobs/uploads/<uuid>
   580  Range: bytes=0-<offset>
   581  Docker-Upload-UUID: <uuid>
   582  ```
   583  
   584  Note that the HTTP `Range` header byte ranges are inclusive and that will be
   585  honored, even in non-standard use cases.
   586  
   587  ##### Monolithic Upload
   588  
   589  A monolithic upload is simply a chunked upload with a single chunk and may be
   590  favored by clients that would like to avoided the complexity of chunking. To
   591  carry out a "monolithic" upload, one can simply put the entire content blob to
   592  the provided URL:
   593  
   594  ```
   595  PUT /v2/<name>/blobs/uploads/<uuid>?digest=<digest>
   596  Content-Length: <size of layer>
   597  Content-Type: application/octet-stream
   598  
   599  <Layer Binary Data>
   600  ```
   601  
   602  The "digest" parameter must be included with the PUT request. Please see the
   603  _Completed Upload_ section for details on the parameters and expected
   604  responses.
   605  
   606  Additionally, the upload can be completed with a single `POST` request to
   607  the uploads endpoint, including the "size" and "digest" parameters:
   608  
   609  ```
   610  POST /v2/<name>/blobs/uploads/?digest=<digest>
   611  Content-Length: <size of layer>
   612  Content-Type: application/octet-stream
   613  
   614  <Layer Binary Data>
   615  ```
   616  
   617  On the registry service, this should allocate a download, accept and verify
   618  the data and return the same  response as the final chunk of an upload. If the
   619  POST request fails collecting the data in any way, the registry should attempt
   620  to return an error response to the client with the `Location` header providing
   621  a place to continue the download.
   622  
   623  The single `POST` method is provided for convenience and most clients should
   624  implement `POST` + `PUT` to support reliable resume of uploads.
   625  
   626  ##### Chunked Upload
   627  
   628  To carry out an upload of a chunk, the client can specify a range header and
   629  only include that part of the layer file:
   630  
   631  ```
   632  PATCH /v2/<name>/blobs/uploads/<uuid>
   633  Content-Length: <size of chunk>
   634  Content-Range: <start of range>-<end of range>
   635  Content-Type: application/octet-stream
   636  
   637  <Layer Chunk Binary Data>
   638  ```
   639  
   640  There is no enforcement on layer chunk splits other than that the server must
   641  receive them in order. The server may enforce a minimum chunk size. If the
   642  server cannot accept the chunk, a `416 Requested Range Not Satisfiable`
   643  response will be returned and will include a `Range` header indicating the
   644  current status:
   645  
   646  ```
   647  416 Requested Range Not Satisfiable
   648  Location: /v2/<name>/blobs/uploads/<uuid>
   649  Range: 0-<last valid range>
   650  Content-Length: 0
   651  Docker-Upload-UUID: <uuid>
   652  ```
   653  
   654  If this response is received, the client should resume from the "last valid
   655  range" and upload the subsequent chunk. A 416 will be returned under the
   656  following conditions:
   657  
   658  - Invalid Content-Range header format
   659  - Out of order chunk: the range of the next chunk must start immediately after
   660    the "last valid range" from the previous response.
   661  
   662  When a chunk is accepted as part of the upload, a `202 Accepted` response will
   663  be returned, including a `Range` header with the current upload status:
   664  
   665  ```
   666  202 Accepted
   667  Location: /v2/<name>/blobs/uploads/<uuid>
   668  Range: bytes=0-<offset>
   669  Content-Length: 0
   670  Docker-Upload-UUID: <uuid>
   671  ```
   672  
   673  ##### Completed Upload
   674  
   675  For an upload to be considered complete, the client must submit a `PUT`
   676  request on the upload endpoint with a digest parameter. If it is not provided,
   677  the upload will not be considered complete. The format for the final chunk
   678  will be as follows:
   679  
   680  ```
   681  PUT /v2/<name>/blob/uploads/<uuid>?digest=<digest>
   682  Content-Length: <size of chunk>
   683  Content-Range: <start of range>-<end of range>
   684  Content-Type: application/octet-stream
   685  
   686  <Last Layer Chunk Binary Data>
   687  ```
   688  
   689  Optionally, if all chunks have already been uploaded, a `PUT` request with a
   690  `digest` parameter and zero-length body may be sent to complete and validated
   691  the upload. Multiple "digest" parameters may be provided with different
   692  digests. The server may verify none or all of them but _must_ notify the
   693  client if the content is rejected.
   694  
   695  When the last chunk is received and the layer has been validated, the client
   696  will receive a `201 Created` response:
   697  
   698  ```
   699  201 Created
   700  Location: /v2/<name>/blobs/<digest>
   701  Content-Length: 0
   702  Docker-Content-Digest: <digest>
   703  ```
   704  
   705  The `Location` header will contain the registry URL to access the accepted
   706  layer file. The `Docker-Content-Digest` header returns the canonical digest of
   707  the uploaded blob which may differ from the provided digest. Most clients may
   708  ignore the value but if it is used, the client should verify the value against
   709  the uploaded blob data.
   710  
   711  ###### Digest Parameter
   712  
   713  The "digest" parameter is designed as an opaque parameter to support
   714  verification of a successful transfer. For example, a HTTP URI parameter
   715  might be as follows:
   716  
   717  ```
   718  sha256:6c3c624b58dbbcd3c0dd82b4c53f04194d1247c6eebdaab7c610cf7d66709b3b
   719  ```
   720  
   721  Given this parameter, the registry will verify that the provided content does
   722  match this digest.
   723  
   724  ##### Canceling an Upload
   725  
   726  An upload can be cancelled by issuing a DELETE request to the upload endpoint.
   727  The format will be as follows:
   728  
   729  ```
   730  DELETE /v2/<name>/blobs/uploads/<uuid>
   731  ```
   732  
   733  After this request is issued, the upload uuid will no longer be valid and the
   734  registry server will dump all intermediate data. While uploads will time out
   735  if not completed, clients should issue this request if they encounter a fatal
   736  error but still have the ability to issue an http request.
   737  
   738  ##### Cross Repository Blob Mount
   739  
   740  A blob may be mounted from another repository that the client has read access
   741  to, removing the need to upload a blob already known to the registry. To issue
   742  a blob mount instead of an upload, a POST request should be issued in the
   743  following format:
   744  
   745  ```
   746  POST /v2/<name>/blobs/uploads/?mount=<digest>&from=<repository name>
   747  Content-Length: 0
   748  ```
   749  
   750  If the blob is successfully mounted, the client will receive a `201 Created`
   751  response:
   752  
   753  ```
   754  201 Created
   755  Location: /v2/<name>/blobs/<digest>
   756  Content-Length: 0
   757  Docker-Content-Digest: <digest>
   758  ```
   759  
   760  The `Location` header will contain the registry URL to access the accepted
   761  layer file. The `Docker-Content-Digest` header returns the canonical digest of
   762  the uploaded blob which may differ from the provided digest. Most clients may
   763  ignore the value but if it is used, the client should verify the value against
   764  the uploaded blob data.
   765  
   766  If a mount fails due to invalid repository or digest arguments, the registry
   767  will fall back to the standard upload behavior and return a `202 Accepted` with
   768  the upload URL in the `Location` header:
   769  
   770  ```
   771  202 Accepted
   772  Location: /v2/<name>/blobs/uploads/<uuid>
   773  Range: bytes=0-<offset>
   774  Content-Length: 0
   775  Docker-Upload-UUID: <uuid>
   776  ```
   777  
   778  This behavior is consistent with older versions of the registry, which do not
   779  recognize the repository mount query parameters.
   780  
   781  Note: a client may issue a HEAD request to check existence of a blob in a source
   782  repository to distinguish between the registry not supporting blob mounts and
   783  the blob not existing in the expected repository.
   784  
   785  ##### Errors
   786  
   787  If an 502, 503 or 504 error is received, the client should assume that the
   788  download can proceed due to a temporary condition, honoring the appropriate
   789  retry mechanism. Other 5xx errors should be treated as terminal.
   790  
   791  If there is a problem with the upload, a 4xx error will be returned indicating
   792  the problem. After receiving a 4xx response (except 416, as called out above),
   793  the upload will be considered failed and the client should take appropriate
   794  action.
   795  
   796  Note that the upload url will not be available forever. If the upload uuid is
   797  unknown to the registry, a `404 Not Found` response will be returned and the
   798  client must restart the upload process.
   799  
   800  ### Deleting a Layer
   801  
   802  A layer may be deleted from the registry via its `name` and `digest`. A
   803  delete may be issued with the following request format:
   804  
   805      DELETE /v2/<name>/blobs/<digest>
   806  
   807  If the blob exists and has been successfully deleted, the following response
   808  will be issued:
   809  
   810      202 Accepted
   811      Content-Length: None
   812  
   813  If the blob had already been deleted or did not exist, a `404 Not Found`
   814  response will be issued instead.
   815  
   816  If a layer is deleted which is referenced by a manifest in the registry,
   817  then the complete images will not be resolvable.
   818  
   819  #### Pushing an Image Manifest
   820  
   821  Once all of the layers for an image are uploaded, the client can upload the
   822  image manifest. An image can be pushed using the following request format:
   823  
   824      PUT /v2/<name>/manifests/<reference>
   825  
   826      {
   827         "name": <name>,
   828         "tag": <tag>,
   829         "fsLayers": [
   830            {
   831               "blobSum": <digest>
   832            },
   833            ...
   834          ]
   835         ],
   836         "history": <v1 images>,
   837         "signature": <JWS>,
   838         ...
   839      }
   840  
   841  The `name` and `reference` fields of the response body must match those specified in
   842  the URL. The `reference` field may be a "tag" or a "digest".
   843  
   844  If there is a problem with pushing the manifest, a relevant 4xx response will
   845  be returned with a JSON error message. Please see the _PUT Manifest section
   846  for details on possible error codes that may be returned.
   847  
   848  If one or more layers are unknown to the registry, `BLOB_UNKNOWN` errors are
   849  returned. The `detail` field of the error response will have a `digest` field
   850  identifying the missing blob. An error is returned for each unknown blob. The
   851  response format is as follows:
   852  
   853      {
   854          "errors:" [{
   855                  "code": "BLOB_UNKNOWN",
   856                  "message": "blob unknown to registry",
   857                  "detail": {
   858                      "digest": <digest>
   859                  }
   860              },
   861              ...
   862          ]
   863      }
   864  
   865  ### Listing Repositories
   866  
   867  Images are stored in collections, known as a _repository_, which is keyed by a
   868  `name`, as seen throughout the API specification. A registry instance may
   869  contain several repositories. The list of available repositories is made
   870  available through the _catalog_.
   871  
   872  The catalog for a given registry can be retrieved with the following request:
   873  
   874  ```
   875  GET /v2/_catalog
   876  ```
   877  
   878  The response will be in the following format:
   879  
   880  ```
   881  200 OK
   882  Content-Type: application/json
   883  
   884  {
   885    "repositories": [
   886      <name>,
   887      ...
   888    ]
   889  }
   890  ```
   891  
   892  Note that the contents of the response are specific to the registry
   893  implementation. Some registries may opt to provide a full catalog output,
   894  limit it based on the user's access level or omit upstream results, if
   895  providing mirroring functionality. Subsequently, the presence of a repository
   896  in the catalog listing only means that the registry *may* provide access to
   897  the repository at the time of the request. Conversely, a missing entry does
   898  *not* mean that the registry does not have the repository. More succinctly,
   899  the presence of a repository only guarantees that it is there but not that it
   900  is _not_ there.
   901  
   902  For registries with a large number of repositories, this response may be quite
   903  large. If such a response is expected, one should use pagination. A registry
   904  may also limit the amount of responses returned even if pagination was not
   905  explicitly requested. In this case the `Link` header will be returned along
   906  with the results, and subsequent results can be obtained by following the link
   907  as if pagination had been initially requested.
   908  
   909  For details of the `Link` header, please see the _Pagination_ section.
   910  
   911  #### Pagination
   912  
   913  Paginated catalog results can be retrieved by adding an `n` parameter to the
   914  request URL, declaring that the response should be limited to `n` results.
   915  Starting a paginated flow begins as follows:
   916  
   917  ```
   918  GET /v2/_catalog?n=<integer>
   919  ```
   920  
   921  The above specifies that a catalog response should be returned, from the start of
   922  the result set, ordered lexically, limiting the number of results to `n`. The
   923  response to such a request would look as follows:
   924  
   925  ```
   926  200 OK
   927  Content-Type: application/json
   928  Link: <<url>?n=<n from the request>&last=<last repository in response>>; rel="next"
   929  
   930  {
   931    "repositories": [
   932      <name>,
   933      ...
   934    ]
   935  }
   936  ```
   937  
   938  The above includes the _first_ `n` entries from the result set. To get the
   939  _next_ `n` entries, one can create a URL where the argument `last` has the
   940  value from `repositories[len(repositories)-1]`. If there are indeed more
   941  results, the URL for the next block is encoded in an
   942  [RFC5988](https://tools.ietf.org/html/rfc5988) `Link` header, as a "next"
   943  relation. The presence of the `Link` header communicates to the client that
   944  the entire result set has not been returned and another request must be
   945  issued. If the header is not present, the client can assume that all results
   946  have been recieved.
   947  
   948  > __NOTE:__ In the request template above, note that the brackets
   949  > are required. For example, if the url is
   950  > `http://example.com/v2/_catalog?n=20&last=b`, the value of the header would
   951  > be `<http://example.com/v2/_catalog?n=20&last=b>; rel="next"`. Please see
   952  > [RFC5988](https://tools.ietf.org/html/rfc5988) for details.
   953  
   954  Compliant client implementations should always use the `Link` header
   955  value when proceeding through results linearly. The client may construct URLs
   956  to skip forward in the catalog.
   957  
   958  To get the next result set, a client would issue the request as follows, using
   959  the URL encoded in the described `Link` header:
   960  
   961  ```
   962  GET /v2/_catalog?n=<n from the request>&last=<last repository value from previous response>
   963  ```
   964  
   965  The above process should then be repeated until the `Link` header is no longer
   966  set.
   967  
   968  The catalog result set is represented abstractly as a lexically sorted list,
   969  where the position in that list can be specified by the query term `last`. The
   970  entries in the response start _after_ the term specified by `last`, up to `n`
   971  entries.
   972  
   973  The behavior of `last` is quite simple when demonstrated with an example. Let
   974  us say the registry has the following repositories:
   975  
   976  ```
   977  a
   978  b
   979  c
   980  d
   981  ```
   982  
   983  If the value of `n` is 2, _a_ and _b_ will be returned on the first response.
   984  The `Link` header returned on the response will have `n` set to 2 and last set
   985  to _b_:
   986  
   987  ```
   988  Link: <<url>?n=2&last=b>; rel="next"
   989  ```
   990  
   991  The client can then issue the request with above value from the `Link` header,
   992  receiving the values _c_ and _d_. Note that n may change on second to last
   993  response or be omitted fully, if the server may so choose.
   994  
   995  ### Listing Image Tags
   996  
   997  It may be necessary to list all of the tags under a given repository. The tags
   998  for an image repository can be retrieved with the following request:
   999  
  1000      GET /v2/<name>/tags/list
  1001  
  1002  The response will be in the following format:
  1003  
  1004      200 OK
  1005      Content-Type: application/json
  1006  
  1007      {
  1008          "name": <name>,
  1009          "tags": [
  1010              <tag>,
  1011              ...
  1012          ]
  1013      }
  1014  
  1015  For repositories with a large number of tags, this response may be quite
  1016  large. If such a response is expected, one should use the pagination.
  1017  
  1018  #### Pagination
  1019  
  1020  Paginated tag results can be retrieved by adding the appropriate parameters to
  1021  the request URL described above. The behavior of tag pagination is identical
  1022  to that specified for catalog pagination. We cover a simple flow to highlight
  1023  any differences.
  1024  
  1025  Starting a paginated flow may begin as follows:
  1026  
  1027  ```
  1028  GET /v2/<name>/tags/list?n=<integer>
  1029  ```
  1030  
  1031  The above specifies that a tags response should be returned, from the start of
  1032  the result set, ordered lexically, limiting the number of results to `n`. The
  1033  response to such a request would look as follows:
  1034  
  1035  ```
  1036  200 OK
  1037  Content-Type: application/json
  1038  Link: <<url>?n=<n from the request>&last=<last tag value from previous response>>; rel="next"
  1039  
  1040  {
  1041    "name": <name>,
  1042    "tags": [
  1043      <tag>,
  1044      ...
  1045    ]
  1046  }
  1047  ```
  1048  
  1049  To get the next result set, a client would issue the request as follows, using
  1050  the value encoded in the [RFC5988](https://tools.ietf.org/html/rfc5988) `Link`
  1051  header:
  1052  
  1053  ```
  1054  GET /v2/<name>/tags/list?n=<n from the request>&last=<last tag value from previous response>
  1055  ```
  1056  
  1057  The above process should then be repeated until the `Link` header is no longer
  1058  set in the response. The behavior of the `last` parameter, the provided
  1059  response result, lexical ordering and encoding of the `Link` header are
  1060  identical to that of catalog pagination.
  1061  
  1062  ### Deleting an Image
  1063  
  1064  An image may be deleted from the registry via its `name` and `reference`. A
  1065  delete may be issued with the following request format:
  1066  
  1067      DELETE /v2/<name>/manifests/<reference>
  1068  
  1069  For deletes, `reference` *must* be a digest or the delete will fail. If the
  1070  image exists and has been successfully deleted, the following response will be
  1071  issued:
  1072  
  1073      202 Accepted
  1074      Content-Length: None
  1075  
  1076  If the image had already been deleted or did not exist, a `404 Not Found`
  1077  response will be issued instead.
  1078  
  1079  ## Detail
  1080  
  1081  > **Note**: This section is still under construction. For the purposes of
  1082  > implementation, if any details below differ from the described request flows
  1083  > above, the section below should be corrected. When they match, this note
  1084  > should be removed.
  1085  
  1086  The behavior of the endpoints are covered in detail in this section, organized
  1087  by route and entity. All aspects of the request and responses are covered,
  1088  including headers, parameters and body formats. Examples of requests and their
  1089  corresponding responses, with success and failure, are enumerated.
  1090  
  1091  > **Note**: The sections on endpoint detail are arranged with an example
  1092  > request, a description of the request, followed by information about that
  1093  > request.
  1094  
  1095  A list of methods and URIs are covered in the table below:
  1096  
  1097  |Method|Path|Entity|Description|
  1098  |------|----|------|-----------|
  1099  {{range $route := .RouteDescriptors}}{{range $method := .Methods}}| {{$method.Method}} | `{{$route.Path|prettygorilla}}` | {{$route.Entity}} | {{$method.Description}} |
  1100  {{end}}{{end}}
  1101  
  1102  The detail for each endpoint is covered in the following sections.
  1103  
  1104  ### Errors
  1105  
  1106  The error codes encountered via the API are enumerated in the following table:
  1107  
  1108  |Code|Message|Description|
  1109  |----|-------|-----------|
  1110  {{range $err := .ErrorDescriptors}} `{{$err.Value}}` | {{$err.Message}} | {{$err.Description|removenewlines}}
  1111  {{end}}
  1112  
  1113  {{range $route := .RouteDescriptors}}
  1114  ### {{.Entity}}
  1115  
  1116  {{.Description}}
  1117  
  1118  {{range $method := $route.Methods}}
  1119  
  1120  #### {{.Method}} {{$route.Entity}}
  1121  
  1122  {{.Description}}
  1123  
  1124  {{if .Requests}}{{range .Requests}}{{if .Name}}
  1125  ##### {{.Name}}{{end}}
  1126  
  1127  ```
  1128  {{$method.Method}} {{$route.Path|prettygorilla}}{{range $i, $param := .QueryParameters}}{{if eq $i 0}}?{{else}}&{{end}}{{$param.Name}}={{$param.Format}}{{end}}{{range .Headers}}
  1129  {{.Name}}: {{.Format}}{{end}}{{if .Body.ContentType}}
  1130  Content-Type: {{.Body.ContentType}}{{end}}{{if .Body.Format}}
  1131  
  1132  {{.Body.Format}}{{end}}
  1133  ```
  1134  
  1135  {{.Description}}
  1136  
  1137  {{if or .Headers .PathParameters .QueryParameters}}
  1138  The following parameters should be specified on the request:
  1139  
  1140  |Name|Kind|Description|
  1141  |----|----|-----------|
  1142  {{range .Headers}}|`{{.Name}}`|header|{{.Description}}|
  1143  {{end}}{{range .PathParameters}}|`{{.Name}}`|path|{{.Description}}|
  1144  {{end}}{{range .QueryParameters}}|`{{.Name}}`|query|{{.Description}}|
  1145  {{end}}{{end}}
  1146  
  1147  {{if .Successes}}
  1148  {{range .Successes}}
  1149  ###### On Success: {{if .Name}}{{.Name}}{{else}}{{.StatusCode | statustext}}{{end}}
  1150  
  1151  ```
  1152  {{.StatusCode}} {{.StatusCode | statustext}}{{range .Headers}}
  1153  {{.Name}}: {{.Format}}{{end}}{{if .Body.ContentType}}
  1154  Content-Type: {{.Body.ContentType}}{{end}}{{if .Body.Format}}
  1155  
  1156  {{.Body.Format}}{{end}}
  1157  ```
  1158  
  1159  {{.Description}}
  1160  {{if .Fields}}The following fields may be returned in the response body:
  1161  
  1162  |Name|Description|
  1163  |----|-----------|
  1164  {{range .Fields}}|`{{.Name}}`|{{.Description}}|
  1165  {{end}}{{end}}{{if .Headers}}
  1166  The following headers will be returned with the response:
  1167  
  1168  |Name|Description|
  1169  |----|-----------|
  1170  {{range .Headers}}|`{{.Name}}`|{{.Description}}|
  1171  {{end}}{{end}}{{end}}{{end}}
  1172  
  1173  {{if .Failures}}
  1174  {{range .Failures}}
  1175  ###### On Failure: {{if .Name}}{{.Name}}{{else}}{{.StatusCode | statustext}}{{end}}
  1176  
  1177  ```
  1178  {{.StatusCode}} {{.StatusCode | statustext}}{{range .Headers}}
  1179  {{.Name}}: {{.Format}}{{end}}{{if .Body.ContentType}}
  1180  Content-Type: {{.Body.ContentType}}{{end}}{{if .Body.Format}}
  1181  
  1182  {{.Body.Format}}{{end}}
  1183  ```
  1184  
  1185  {{.Description}}
  1186  {{if .Headers}}
  1187  The following headers will be returned on the response:
  1188  
  1189  |Name|Description|
  1190  |----|-----------|
  1191  {{range .Headers}}|`{{.Name}}`|{{.Description}}|
  1192  {{end}}{{end}}
  1193  
  1194  {{if .ErrorCodes}}
  1195  The error codes that may be included in the response body are enumerated below:
  1196  
  1197  |Code|Message|Description|
  1198  |----|-------|-----------|
  1199  {{range $err := .ErrorCodes}}| `{{$err.Descriptor.Value}}` | {{$err.Descriptor.Message}} | {{$err.Descriptor.Description|removenewlines}} |
  1200  {{end}}
  1201  
  1202  {{end}}{{end}}{{end}}{{end}}{{end}}{{end}}
  1203  
  1204  {{end}}