api.md.tmpl 43 KB

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