workingwithrepository.rst 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. :title: Share Images via Repositories
  2. :description: Repositories allow users to share images.
  3. :keywords: repo, repositories, usage, pull image, push image, image, documentation
  4. .. _working_with_the_repository:
  5. Share Images via Repositories
  6. =============================
  7. A *repository* is a shareable collection of tagged :ref:`images<image_def>`
  8. that together create the file systems for containers. The
  9. repository's name is a label that indicates the provenance of the
  10. repository, i.e. who created it and where the original copy is
  11. located.
  12. You can find one or more repositories hosted on a *registry*. There
  13. can be an implicit or explicit host name as part of the repository
  14. tag. The implicit registry is located at ``index.docker.io``, the home
  15. of "top-level" repositories and the Central Index. This registry may
  16. also include public "user" repositories.
  17. Docker is not only a tool for creating and managing your own
  18. :ref:`containers <container_def>` -- **Docker is also a tool for
  19. sharing**. The Docker project provides a Central Registry to host
  20. public repositories, namespaced by user, and a Central Index which
  21. provides user authentication and search over all the public
  22. repositories. You can host your own Registry too! Docker acts as a
  23. client for these services via ``docker search, pull, login`` and
  24. ``push``.
  25. Local Repositories
  26. ------------------
  27. Docker images which have been created and labeled on your local Docker server
  28. need to be pushed to a Public or Private registry to be shared.
  29. .. _using_public_repositories:
  30. Public Repositories
  31. -------------------
  32. There are two types of public repositories: *top-level* repositories
  33. which are controlled by the Docker team, and *user* repositories
  34. created by individual contributors. Anyone can read from these
  35. repositories -- they really help people get started quickly! You could
  36. also use :ref:`using_private_repositories` if you need to keep control
  37. of who accesses your images, but we will only refer to public
  38. repositories in these examples.
  39. * Top-level repositories can easily be recognized by **not** having a
  40. ``/`` (slash) in their name. These repositories can generally be
  41. trusted.
  42. * User repositories always come in the form of
  43. ``<username>/<repo_name>``. This is what your published images will
  44. look like if you push to the public Central Registry.
  45. * Only the authenticated user can push to their *username* namespace
  46. on the Central Registry.
  47. * User images are not checked, it is therefore up to you whether or
  48. not you trust the creator of this image.
  49. .. _searching_central_index:
  50. Find Public Images on the Central Index
  51. ---------------------------------------
  52. You can search the Central Index `online <https://index.docker.io>`_
  53. or using the command line interface. Searching can find images by name, user
  54. name or description:
  55. .. code-block:: bash
  56. $ sudo docker help search
  57. Usage: docker search NAME
  58. Search the docker index for images
  59. --no-trunc=false: Don't truncate output
  60. $ sudo docker search centos
  61. Found 25 results matching your query ("centos")
  62. NAME DESCRIPTION
  63. centos
  64. slantview/centos-chef-solo CentOS 6.4 with chef-solo.
  65. ...
  66. There you can see two example results: ``centos`` and
  67. ``slantview/centos-chef-solo``. The second result shows that it comes
  68. from the public repository of a user, ``slantview/``, while the first
  69. result (``centos``) doesn't explicitly list a repository so it comes
  70. from the trusted Central Repository. The ``/`` character separates a
  71. user's repository and the image name.
  72. Once you have found the image name, you can download it:
  73. .. code-block:: bash
  74. # sudo docker pull <value>
  75. $ sudo docker pull centos
  76. Pulling repository centos
  77. 539c0211cd76: Download complete
  78. What can you do with that image? Check out the :ref:`example_list`
  79. and, when you're ready with your own image, come back here to learn
  80. how to share it.
  81. Contributing to the Central Registry
  82. ------------------------------------
  83. Anyone can pull public images from the Central Registry, but if you
  84. would like to share one of your own images, then you must register a
  85. unique user name first. You can create your username and login on the
  86. `central Docker Index online
  87. <https://index.docker.io/account/signup/>`_, or by running
  88. .. code-block:: bash
  89. sudo docker login
  90. This will prompt you for a username, which will become a public
  91. namespace for your public repositories.
  92. If your username is available then ``docker`` will also prompt you to
  93. enter a password and your e-mail address. It will then automatically
  94. log you in. Now you're ready to commit and push your own images!
  95. .. _container_commit:
  96. Committing a Container to a Named Image
  97. ---------------------------------------
  98. When you make changes to an existing image, those changes get saved to
  99. a container's file system. You can then promote that container to
  100. become an image by making a ``commit``. In addition to converting the
  101. container to an image, this is also your opportunity to name the
  102. image, specifically a name that includes your user name from the
  103. Central Docker Index (as you did a ``login`` above) and a meaningful
  104. name for the image.
  105. .. code-block:: bash
  106. # format is "sudo docker commit <container_id> <username>/<imagename>"
  107. $ sudo docker commit $CONTAINER_ID myname/kickassapp
  108. .. _image_push:
  109. Pushing a repository to its registry
  110. ------------------------------------
  111. In order to push an repository to its registry you need to have named an image,
  112. or committed your container to a named image (see above)
  113. Now you can push this repository to the registry designated by its name
  114. or tag.
  115. .. code-block:: bash
  116. # format is "docker push <username>/<repo_name>"
  117. $ sudo docker push myname/kickassapp
  118. .. _using_private_repositories:
  119. Trusted Builds
  120. --------------
  121. Trusted Builds automate the building and updating of images from GitHub, directly
  122. on ``docker.io`` servers. It works by adding a commit hook to your selected repository,
  123. triggering a build and update when you push a commit.
  124. To setup a trusted build
  125. ++++++++++++++++++++++++
  126. #. Create a `Docker Index account <https://index.docker.io/>`_ and login.
  127. #. Link your GitHub account through the ``Link Accounts`` menu.
  128. #. `Configure a Trusted build <https://index.docker.io/builds/>`_.
  129. #. Pick a GitHub project that has a ``Dockerfile`` that you want to build.
  130. #. Pick the branch you want to build (the default is the ``master`` branch).
  131. #. Give the Trusted Build a name.
  132. #. Assign an optional Docker tag to the Build.
  133. #. Specify where the ``Dockerfile`` is located. The default is ``/``.
  134. Once the Trusted Build is configured it will automatically trigger a build, and
  135. in a few minutes, if there are no errors, you will see your new trusted build
  136. on the Docker Index. It will will stay in sync with your GitHub repo until you
  137. deactivate the Trusted Build.
  138. If you want to see the status of your Trusted Builds you can go to your
  139. `Trusted Builds page <https://index.docker.io/builds/>`_ on the Docker index,
  140. and it will show you the status of your builds, and the build history.
  141. Once you've created a Trusted Build you can deactivate or delete it. You cannot
  142. however push to a Trusted Build with the ``docker push`` command. You can only
  143. manage it by committing code to your GitHub repository.
  144. You can create multiple Trusted Builds per repository and configure them to
  145. point to specific ``Dockerfile``'s or Git branches.
  146. Private Registry
  147. ----------------
  148. Private registries and private shared repositories are
  149. only possible by hosting `your own registry
  150. <https://github.com/dotcloud/docker-registry>`_. To push or pull to a
  151. repository on your own registry, you must prefix the tag with the
  152. address of the registry's host (a ``.`` or ``:`` is used to identify a host),
  153. like this:
  154. .. code-block:: bash
  155. # Tag to create a repository with the full registry location.
  156. # The location (e.g. localhost.localdomain:5000) becomes
  157. # a permanent part of the repository name
  158. sudo docker tag 0u812deadbeef localhost.localdomain:5000/repo_name
  159. # Push the new repository to its home location on localhost
  160. sudo docker push localhost.localdomain:5000/repo_name
  161. Once a repository has your registry's host name as part of the tag,
  162. you can push and pull it like any other repository, but it will
  163. **not** be searchable (or indexed at all) in the Central Index, and
  164. there will be no user name checking performed. Your registry will
  165. function completely independently from the Central Index.
  166. .. raw:: html
  167. <iframe width="640" height="360"
  168. src="//www.youtube.com/embed/CAewZCBT4PI?rel=0" frameborder="0"
  169. allowfullscreen></iframe>
  170. .. seealso:: `Docker Blog: How to use your own registry
  171. <http://blog.docker.io/2013/07/how-to-use-your-own-registry/>`_
  172. Authentication file
  173. -------------------
  174. The authentication is stored in a json file, ``.dockercfg`` located in your
  175. home directory. It supports multiple registry urls.
  176. ``docker login`` will create the "https://index.docker.io/v1/" key.
  177. ``docker login https://my-registry.com`` will create the "https://my-registry.com" key.
  178. For example:
  179. .. code-block:: json
  180. {
  181. "https://index.docker.io/v1/": {
  182. "auth": "xXxXxXxXxXx=",
  183. "email": "email@example.com"
  184. },
  185. "https://my-registry.com": {
  186. "auth": "XxXxXxXxXxX=",
  187. "email": "email@my-registry.com"
  188. }
  189. }
  190. The ``auth`` field represents ``base64(<username>:<password>)``