api.md.tmpl 42 KB

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