github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/docs/sources/reference/api/hub_registry_spec.md (about) 1 page_title: Registry documentation 2 page_description: Documentation for docker Registry and Registry API 3 page_keywords: docker, registry, api, hub 4 5 # The Docker Hub and the Registry 1.0 spec 6 7 ## The three roles 8 9 There are three major components playing a role in the Docker ecosystem. 10 11 ### Docker Hub 12 13 The Docker Hub is responsible for centralizing information about: 14 15 - User accounts 16 - Checksums of the images 17 - Public namespaces 18 19 The Docker Hub has different components: 20 21 - Web UI 22 - Meta-data store (comments, stars, list public repositories) 23 - Authentication service 24 - Tokenization 25 26 The Docker Hub is authoritative for that information. 27 28 There is only one instance of the Docker Hub, run and 29 managed by Docker Inc. 30 31 ### Docker Registry 1.0 32 33 The 1.0 registry has the following characteristics: 34 35 - It stores the images and the graph for a set of repositories 36 - It does not have user accounts data 37 - It has no notion of user accounts or authorization 38 - It delegates authentication and authorization to the Docker Hub Auth 39 service using tokens 40 - It supports different storage backends (S3, cloud files, local FS) 41 - It doesn't have a local database 42 - [Source Code](https://github.com/docker/docker-registry) 43 44 We expect that there will be multiple registries out there. To help you 45 grasp the context, here are some examples of registries: 46 47 - **sponsor registry**: such a registry is provided by a third-party 48 hosting infrastructure as a convenience for their customers and the 49 Docker community as a whole. Its costs are supported by the third 50 party, but the management and operation of the registry are 51 supported by Docker, Inc. It features read/write access, and delegates 52 authentication and authorization to the Docker Hub. 53 - **mirror registry**: such a registry is provided by a third-party 54 hosting infrastructure but is targeted at their customers only. Some 55 mechanism (unspecified to date) ensures that public images are 56 pulled from a sponsor registry to the mirror registry, to make sure 57 that the customers of the third-party provider can `docker pull` 58 those images locally. 59 - **vendor registry**: such a registry is provided by a software 60 vendor who wants to distribute docker images. It would be operated 61 and managed by the vendor. Only users authorized by the vendor would 62 be able to get write access. Some images would be public (accessible 63 for anyone), others private (accessible only for authorized users). 64 Authentication and authorization would be delegated to the Docker Hub. 65 The goal of vendor registries is to let someone do `docker pull 66 basho/riak1.3` and automatically push from the vendor registry 67 (instead of a sponsor registry); i.e., vendors get all the convenience of a 68 sponsor registry, while retaining control on the asset distribution. 69 - **private registry**: such a registry is located behind a firewall, 70 or protected by an additional security layer (HTTP authorization, 71 SSL client-side certificates, IP address authorization...). The 72 registry is operated by a private entity, outside of Docker's 73 control. It can optionally delegate additional authorization to the 74 Docker Hub, but it is not mandatory. 75 76 > **Note:** The latter implies that while HTTP is the protocol 77 > of choice for a registry, multiple schemes are possible (and 78 > in some cases, trivial): 79 > 80 > - HTTP with GET (and PUT for read-write registries); 81 > - local mount point; 82 > - remote docker addressed through SSH. 83 84 The latter would only require two new commands in Docker, e.g., 85 `registryget` and `registryput`, 86 wrapping access to the local filesystem (and optionally doing 87 consistency checks). Authentication and authorization are then delegated 88 to SSH (e.g., with public keys). 89 90 ### Docker 91 92 On top of being a runtime for LXC, Docker is the Registry client. It 93 supports: 94 95 - Push / Pull on the registry 96 - Client authentication on the Docker Hub 97 98 ## Workflow 99 100 ### Pull 101 102 ![](/static_files/docker_pull_chart.png) 103 104 1. Contact the Docker Hub to know where I should download “samalba/busybox” 105 2. Docker Hub replies: a. `samalba/busybox` is on Registry A b. here are the 106 checksums for `samalba/busybox` (for all layers) c. token 107 3. Contact Registry A to receive the layers for `samalba/busybox` (all of 108 them to the base image). Registry A is authoritative for “samalba/busybox” 109 but keeps a copy of all inherited layers and serve them all from the same 110 location. 111 4. registry contacts Docker Hub to verify if token/user is allowed to download images 112 5. Docker Hub returns true/false lettings registry know if it should proceed or error 113 out 114 6. Get the payload for all layers 115 116 It's possible to run: 117 118 $ docker pull https://<registry>/repositories/samalba/busybox 119 120 In this case, Docker bypasses the Docker Hub. However the security is not 121 guaranteed (in case Registry A is corrupted) because there won't be any 122 checksum checks. 123 124 Currently registry redirects to s3 urls for downloads, going forward all 125 downloads need to be streamed through the registry. The Registry will 126 then abstract the calls to S3 by a top-level class which implements 127 sub-classes for S3 and local storage. 128 129 Token is only returned when the `X-Docker-Token` 130 header is sent with request. 131 132 Basic Auth is required to pull private repos. Basic auth isn't required 133 for pulling public repos, but if one is provided, it needs to be valid 134 and for an active account. 135 136 **API (pulling repository foo/bar):** 137 138 1. (Docker -> Docker Hub) GET /v1/repositories/foo/bar/images: 139 140 **Headers**: 141 142 Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 143 X-Docker-Token: true 144 145 **Action**: 146 147 (looking up the foo/bar in db and gets images and checksums 148 for that repo (all if no tag is specified, if tag, only 149 checksums for those tags) see part 4.4.1) 150 151 2. (Docker Hub -> Docker) HTTP 200 OK 152 153 **Headers**: 154 155 Authorization: Token 156 signature=123abc,repository=”foo/bar”,access=write 157 X-Docker-Endpoints: registry.docker.io [,registry2.docker.io] 158 159 **Body**: 160 161 Jsonified checksums (see part 4.4.1) 162 163 3. (Docker -> Registry) GET /v1/repositories/foo/bar/tags/latest 164 165 **Headers**: 166 167 Authorization: Token 168 signature=123abc,repository=”foo/bar”,access=write 169 170 4. (Registry -> Docker Hub) GET /v1/repositories/foo/bar/images 171 172 **Headers**: 173 174 Authorization: Token 175 signature=123abc,repository=”foo/bar”,access=read 176 177 **Body**: 178 179 <ids and checksums in payload> 180 181 **Action**: 182 183 (Lookup token see if they have access to pull.) 184 185 If good: 186 HTTP 200 OK Docker Hub will invalidate the token 187 188 If bad: 189 HTTP 401 Unauthorized 190 191 5. (Docker -> Registry) GET /v1/images/928374982374/ancestry 192 193 **Action**: 194 195 (for each image id returned in the registry, fetch /json + /layer) 196 197 > **Note**: 198 > If someone makes a second request, then we will always give a new token, 199 > never reuse tokens. 200 201 ### Push 202 203 ![](/static_files/docker_push_chart.png) 204 205 1. Contact the Docker Hub to allocate the repository name “samalba/busybox” 206 (authentication required with user credentials) 207 2. If authentication works and namespace available, “samalba/busybox” 208 is allocated and a temporary token is returned (namespace is marked 209 as initialized in Docker Hub) 210 3. Push the image on the registry (along with the token) 211 4. Registry A contacts the Docker Hub to verify the token (token must 212 corresponds to the repository name) 213 5. Docker Hub validates the token. Registry A starts reading the stream 214 pushed by docker and store the repository (with its images) 215 6. docker contacts the Docker Hub to give checksums for upload images 216 217 > **Note:** 218 > **It's possible not to use the Docker Hub at all!** In this case, a deployed 219 > version of the Registry is deployed to store and serve images. Those 220 > images are not authenticated and the security is not guaranteed. 221 222 > **Note:** 223 > **Docker Hub can be replaced!** For a private Registry deployed, a custom 224 > Docker Hub can be used to serve and validate token according to different 225 > policies. 226 227 Docker computes the checksums and submit them to the Docker Hub at the end of 228 the push. When a repository name does not have checksums on the Docker Hub, 229 it means that the push is in progress (since checksums are submitted at 230 the end). 231 232 **API (pushing repos foo/bar):** 233 234 1. (Docker -> Docker Hub) PUT /v1/repositories/foo/bar/ 235 236 **Headers**: 237 238 Authorization: Basic sdkjfskdjfhsdkjfh== X-Docker-Token: 239 true 240 241 **Action**: 242 243 - in Docker Hub, we allocated a new repository, and set to 244 initialized 245 246 **Body**: 247 248 (The body contains the list of images that are going to be 249 pushed, with empty checksums. The checksums will be set at 250 the end of the push): 251 252 [{“id”: “9e89cc6f0bc3c38722009fe6857087b486531f9a779a0c17e3ed29dae8f12c4f”}] 253 254 2. (Docker Hub -> Docker) 200 Created 255 256 **Headers**: 257 258 WWW-Authenticate: Token 259 signature=123abc,repository=”foo/bar”,access=write 260 X-Docker-Endpoints: registry.docker.io [, registry2.docker.io] 261 262 3. (Docker -> Registry) PUT /v1/images/98765432_parent/json 263 264 **Headers**: 265 266 Authorization: Token 267 signature=123abc,repository=”foo/bar”,access=write 268 269 4. (Registry->Docker Hub) GET /v1/repositories/foo/bar/images 270 271 **Headers**: 272 273 Authorization: Token 274 signature=123abc,repository=”foo/bar”,access=write 275 276 **Action**: 277 278 - Docker Hub: 279 will invalidate the token. 280 - Registry: 281 grants a session (if token is approved) and fetches 282 the images id 283 284 5. (Docker -> Registry) PUT /v1/images/98765432_parent/json 285 286 **Headers**: 287 288 Authorization: Token 289 signature=123abc,repository=”foo/bar”,access=write 290 Cookie: (Cookie provided by the Registry) 291 292 6. (Docker -> Registry) PUT /v1/images/98765432/json 293 294 **Headers**: 295 296 Cookie: (Cookie provided by the Registry) 297 298 7. (Docker -> Registry) PUT /v1/images/98765432_parent/layer 299 300 **Headers**: 301 302 Cookie: (Cookie provided by the Registry) 303 304 8. (Docker -> Registry) PUT /v1/images/98765432/layer 305 306 **Headers**: 307 308 X-Docker-Checksum: sha256:436745873465fdjkhdfjkgh 309 310 9. (Docker -> Registry) PUT /v1/repositories/foo/bar/tags/latest 311 312 **Headers**: 313 314 Cookie: (Cookie provided by the Registry) 315 316 **Body**: 317 318 “98765432” 319 320 10. (Docker -> Docker Hub) PUT /v1/repositories/foo/bar/images 321 322 **Headers**: 323 324 Authorization: Basic 123oislifjsldfj== X-Docker-Endpoints: 325 registry1.docker.io (no validation on this right now) 326 327 **Body**: 328 329 (The image, id`s, tags and checksums) 330 [{“id”: 331 “9e89cc6f0bc3c38722009fe6857087b486531f9a779a0c17e3ed29dae8f12c4f”, 332 “checksum”: 333 “b486531f9a779a0c17e3ed29dae8f12c4f9e89cc6f0bc3c38722009fe6857087”}] 334 335 **Return**: 336 337 HTTP 204 338 339 > **Note:** If push fails and they need to start again, what happens in the Docker Hub, 340 > there will already be a record for the namespace/name, but it will be 341 > initialized. Should we allow it, or mark as name already used? One edge 342 > case could be if someone pushes the same thing at the same time with two 343 > different shells. 344 345 If it's a retry on the Registry, Docker has a cookie (provided by the 346 registry after token validation). So the Docker Hub won't have to provide a 347 new token. 348 349 ### Delete 350 351 If you need to delete something from the Docker Hub or registry, we need a 352 nice clean way to do that. Here is the workflow. 353 354 1. Docker contacts the Docker Hub to request a delete of a repository 355 `samalba/busybox` (authentication required with user credentials) 356 2. If authentication works and repository is valid, `samalba/busybox` 357 is marked as deleted and a temporary token is returned 358 3. Send a delete request to the registry for the repository (along with 359 the token) 360 4. Registry A contacts the Docker Hub to verify the token (token must 361 corresponds to the repository name) 362 5. Docker Hub validates the token. Registry A deletes the repository and 363 everything associated to it. 364 6. docker contacts the Docker Hub to let it know it was removed from the 365 registry, the Docker Hub removes all records from the database. 366 367 > **Note**: 368 > The Docker client should present an "Are you sure?" prompt to confirm 369 > the deletion before starting the process. Once it starts it can't be 370 > undone. 371 372 **API (deleting repository foo/bar):** 373 374 1. (Docker -> Docker Hub) DELETE /v1/repositories/foo/bar/ 375 376 **Headers**: 377 378 Authorization: Basic sdkjfskdjfhsdkjfh== X-Docker-Token: 379 true 380 381 **Action**: 382 383 - in Docker Hub, we make sure it is a valid repository, and set 384 to deleted (logically) 385 386 **Body**: 387 388 Empty 389 390 2. (Docker Hub -> Docker) 202 Accepted 391 392 **Headers**: 393 394 WWW-Authenticate: Token 395 signature=123abc,repository=”foo/bar”,access=delete 396 X-Docker-Endpoints: registry.docker.io [, registry2.docker.io] 397 # list of endpoints where this repo lives. 398 399 3. (Docker -> Registry) DELETE /v1/repositories/foo/bar/ 400 401 **Headers**: 402 403 Authorization: Token 404 signature=123abc,repository=”foo/bar”,access=delete 405 406 4. (Registry->Docker Hub) PUT /v1/repositories/foo/bar/auth 407 408 **Headers**: 409 410 Authorization: Token 411 signature=123abc,repository=”foo/bar”,access=delete 412 413 **Action**: 414 415 - Docker Hub: 416 will invalidate the token. 417 - Registry: 418 deletes the repository (if token is approved) 419 420 5. (Registry -> Docker) 200 OK 421 422 200 If success 403 if forbidden 400 if bad request 404 423 if repository isn't found 424 425 6. (Docker -> Docker Hub) DELETE /v1/repositories/foo/bar/ 426 427 **Headers**: 428 429 Authorization: Basic 123oislifjsldfj== X-Docker-Endpoints: 430 registry-1.docker.io (no validation on this right now) 431 432 **Body**: 433 434 Empty 435 436 **Return**: 437 438 HTTP 200 439 440 ## How to use the Registry in standalone mode 441 442 The Docker Hub has two main purposes (along with its fancy social features): 443 444 - Resolve short names (to avoid passing absolute URLs all the time): 445 446 username/projectname -> 447 https://registry.docker.io/users/<username>/repositories/<projectname>/ 448 team/projectname -> 449 https://registry.docker.io/team/<team>/repositories/<projectname>/ 450 451 - Authenticate a user as a repos owner (for a central referenced 452 repository) 453 454 ### Without a Docker Hub 455 456 Using the Registry without the Docker Hub can be useful to store the images 457 on a private network without having to rely on an external entity 458 controlled by Docker Inc. 459 460 In this case, the registry will be launched in a special mode 461 (-standalone? ne? -no-index?). In this mode, the only thing which changes is 462 that Registry will never contact the Docker Hub to verify a token. It will be 463 the Registry owner responsibility to authenticate the user who pushes 464 (or even pulls) an image using any mechanism (HTTP auth, IP based, 465 etc...). 466 467 In this scenario, the Registry is responsible for the security in case 468 of data corruption since the checksums are not delivered by a trusted 469 entity. 470 471 As hinted previously, a standalone registry can also be implemented by 472 any HTTP server handling GET/PUT requests (or even only GET requests if 473 no write access is necessary). 474 475 ### With a Docker Hub 476 477 The Docker Hub data needed by the Registry are simple: 478 479 - Serve the checksums 480 - Provide and authorize a Token 481 482 In the scenario of a Registry running on a private network with the need 483 of centralizing and authorizing, it's easy to use a custom Docker Hub. 484 485 The only challenge will be to tell Docker to contact (and trust) this 486 custom Docker Hub. Docker will be configurable at some point to use a 487 specific Docker Hub, it'll be the private entity responsibility (basically 488 the organization who uses Docker in a private environment) to maintain 489 the Docker Hub and the Docker's configuration among its consumers. 490 491 ## The API 492 493 The first version of the api is available here: 494 [https://github.com/jpetazzo/docker/blob/acd51ecea8f5d3c02b00a08176171c59442df8b3/docs/images-repositories-push-pull.md](https://github.com/jpetazzo/docker/blob/acd51ecea8f5d3c02b00a08176171c59442df8b3/docs/images-repositories-push-pull.md) 495 496 ### Images 497 498 The format returned in the images is not defined here (for layer and 499 JSON), basically because Registry stores exactly the same kind of 500 information as Docker uses to manage them. 501 502 The format of ancestry is a line-separated list of image ids, in age 503 order, i.e. the image's parent is on the last line, the parent of the 504 parent on the next-to-last line, etc.; if the image has no parent, the 505 file is empty. 506 507 GET /v1/images/<image_id>/layer 508 PUT /v1/images/<image_id>/layer 509 GET /v1/images/<image_id>/json 510 PUT /v1/images/<image_id>/json 511 GET /v1/images/<image_id>/ancestry 512 PUT /v1/images/<image_id>/ancestry 513 514 ### Users 515 516 ### Create a user (Docker Hub) 517 518 POST /v1/users: 519 520 **Body**: 521 522 {"email": "[sam@docker.com](mailto:sam%40docker.com)", 523 "password": "toto42", "username": "foobar"`} 524 525 **Validation**: 526 527 - **username**: min 4 character, max 30 characters, must match the 528 regular expression [a-z0-9_]. 529 - **password**: min 5 characters 530 531 **Valid**: 532 533 return HTTP 201 534 535 Errors: HTTP 400 (we should create error codes for possible errors) - 536 invalid json - missing field - wrong format (username, password, email, 537 etc) - forbidden name - name already exists 538 539 > **Note**: 540 > A user account will be valid only if the email has been validated (a 541 > validation link is sent to the email address). 542 543 ### Update a user (Docker Hub) 544 545 PUT /v1/users/<username> 546 547 **Body**: 548 549 {"password": "toto"} 550 551 > **Note**: 552 > We can also update email address, if they do, they will need to reverify 553 > their new email address. 554 555 ### Login (Docker Hub) 556 557 Does nothing else but asking for a user authentication. Can be used to 558 validate credentials. HTTP Basic Auth for now, maybe change in future. 559 560 GET /v1/users 561 562 **Return**: 563 - Valid: HTTP 200 564 - Invalid login: HTTP 401 565 - Account inactive: HTTP 403 Account is not Active 566 567 ### Tags (Registry) 568 569 The Registry does not know anything about users. Even though 570 repositories are under usernames, it's just a namespace for the 571 registry. Allowing us to implement organizations or different namespaces 572 per user later, without modifying the Registry's API. 573 574 The following naming restrictions apply: 575 576 - Namespaces must match the same regular expression as usernames (See 577 4.2.1.) 578 - Repository names must match the regular expression [a-zA-Z0-9-_.] 579 580 ### Get all tags: 581 582 GET /v1/repositories/<namespace>/<repository_name>/tags 583 584 **Return**: HTTP 200 585 [ 586 { 587 "layer": "9e89cc6f", 588 "name": "latest" 589 }, 590 { 591 "layer": "b486531f", 592 "name": "0.1.1", 593 } 594 ] 595 596 **4.3.2 Read the content of a tag (resolve the image id):** 597 598 GET /v1/repositories/<namespace>/<repo_name>/tags/<tag> 599 600 **Return**: 601 602 "9e89cc6f0bc3c38722009fe6857087b486531f9a779a0c17e3ed29dae8f12c4f" 603 604 **4.3.3 Delete a tag (registry):** 605 606 DELETE /v1/repositories/<namespace>/<repo_name>/tags/<tag> 607 608 ### 4.4 Images (Docker Hub) 609 610 For the Docker Hub to “resolve” the repository name to a Registry location, 611 it uses the X-Docker-Endpoints header. In other terms, this requests 612 always add a `X-Docker-Endpoints` to indicate the 613 location of the registry which hosts this repository. 614 615 **4.4.1 Get the images:** 616 617 GET /v1/repositories/<namespace>/<repo_name>/images 618 619 **Return**: HTTP 200 620 [{“id”: 621 “9e89cc6f0bc3c38722009fe6857087b486531f9a779a0c17e3ed29dae8f12c4f”, 622 “checksum”: 623 “[md5:b486531f9a779a0c17e3ed29dae8f12c4f9e89cc6f0bc3c38722009fe6857087](md5:b486531f9a779a0c17e3ed29dae8f12c4f9e89cc6f0bc3c38722009fe6857087)”}] 624 625 ### Add/update the images: 626 627 You always add images, you never remove them. 628 629 PUT /v1/repositories/<namespace>/<repo_name>/images 630 631 **Body**: 632 633 [ {“id”: 634 “9e89cc6f0bc3c38722009fe6857087b486531f9a779a0c17e3ed29dae8f12c4f”, 635 “checksum”: 636 “sha256:b486531f9a779a0c17e3ed29dae8f12c4f9e89cc6f0bc3c38722009fe6857087”} 637 ] 638 639 **Return**: 640 641 204 642 643 ### Repositories 644 645 ### Remove a Repository (Registry) 646 647 DELETE /v1/repositories/<namespace>/<repo_name> 648 649 Return 200 OK 650 651 ### Remove a Repository (Docker Hub) 652 653 This starts the delete process. see 2.3 for more details. 654 655 DELETE /v1/repositories/<namespace>/<repo_name> 656 657 Return 202 OK 658 659 ## Chaining Registries 660 661 It's possible to chain Registries server for several reasons: 662 663 - Load balancing 664 - Delegate the next request to another server 665 666 When a Registry is a reference for a repository, it should host the 667 entire images chain in order to avoid breaking the chain during the 668 download. 669 670 The Docker Hub and Registry use this mechanism to redirect on one or the 671 other. 672 673 Example with an image download: 674 675 On every request, a special header can be returned: 676 677 X-Docker-Endpoints: server1,server2 678 679 On the next request, the client will always pick a server from this 680 list. 681 682 ## Authentication and authorization 683 684 ### On the Docker Hub 685 686 The Docker Hub supports both “Basic” and “Token” challenges. Usually when 687 there is a `401 Unauthorized`, the Docker Hub replies 688 this: 689 690 401 Unauthorized 691 WWW-Authenticate: Basic realm="auth required",Token 692 693 You have 3 options: 694 695 1. Provide user credentials and ask for a token 696 697 **Header**: 698 699 Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 700 X-Docker-Token: true 701 702 In this case, along with the 200 response, you'll get a new token 703 (if user auth is ok): If authorization isn't correct you get a 401 704 response. If account isn't active you will get a 403 response. 705 706 **Response**: 707 708 200 OK 709 X-Docker-Token: Token 710 signature=123abc,repository=”foo/bar”,access=read 711 712 713 2. Provide user credentials only 714 715 **Header**: 716 717 Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 718 719 3. Provide Token 720 721 **Header**: 722 723 Authorization: Token 724 signature=123abc,repository=”foo/bar”,access=read 725 726 ### 6.2 On the Registry 727 728 The Registry only supports the Token challenge: 729 730 401 Unauthorized 731 WWW-Authenticate: Token 732 733 The only way is to provide a token on `401 Unauthorized` 734 responses: 735 736 Authorization: Token signature=123abc,repository="foo/bar",access=read 737 738 Usually, the Registry provides a Cookie when a Token verification 739 succeeded. Every time the Registry passes a Cookie, you have to pass it 740 back the same cookie.: 741 742 200 OK 743 Set-Cookie: session="wD/J7LqL5ctqw8haL10vgfhrb2Q=?foo=UydiYXInCnAxCi4=×tamp=RjEzNjYzMTQ5NDcuNDc0NjQzCi4="; Path=/; HttpOnly 744 745 Next request: 746 747 GET /(...) 748 Cookie: session="wD/J7LqL5ctqw8haL10vgfhrb2Q=?foo=UydiYXInCnAxCi4=×tamp=RjEzNjYzMTQ5NDcuNDc0NjQzCi4=" 749 750 ## Document version 751 752 - 1.0 : May 6th 2013 : initial release 753 - 1.1 : June 1st 2013 : Added Delete Repository and way to handle new 754 source namespace. 755