workingwithrepository.rst 9.0 KB

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