build.rst 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. :title: Build Command
  2. :description: Build a new image from the Dockerfile passed via stdin
  3. :keywords: build, docker, container, documentation
  4. ================================================
  5. ``build`` -- Build a container from a Dockerfile
  6. ================================================
  7. ::
  8. Usage: docker build [OPTIONS] PATH | URL | -
  9. Build a new container image from the source code at PATH
  10. -t="": Repository name (and optionally a tag) to be applied to the resulting image in case of success.
  11. -q=false: Suppress verbose build output.
  12. -no-cache: Do not use the cache when building the image.
  13. When a single Dockerfile is given as URL, then no context is set. When a git repository is set as URL, the repository is used as context
  14. Examples
  15. --------
  16. .. code-block:: bash
  17. sudo docker build .
  18. This will read the ``Dockerfile`` from the current directory. It will
  19. also send any other files and directories found in the current
  20. directory to the ``docker`` daemon.
  21. The contents of this directory would be used by ``ADD`` commands found
  22. within the ``Dockerfile``. This will send a lot of data to the
  23. ``docker`` daemon if the current directory contains a lot of data. If
  24. the absolute path is provided instead of ``.`` then only the files and
  25. directories required by the ADD commands from the ``Dockerfile`` will be
  26. added to the context and transferred to the ``docker`` daemon.
  27. .. code-block:: bash
  28. sudo docker build -t vieux/apache:2.0 .
  29. This will build like the previous example, but it will then tag the
  30. resulting image. The repository name will be ``vieux/apache`` and the
  31. tag will be ``2.0``
  32. .. code-block:: bash
  33. sudo docker build - < Dockerfile
  34. This will read a ``Dockerfile`` from *stdin* without context. Due to
  35. the lack of a context, no contents of any local directory will be sent
  36. to the ``docker`` daemon. ``ADD`` doesn't work when running in this
  37. mode because the absence of the context provides no source files to
  38. copy to the container.
  39. .. code-block:: bash
  40. sudo docker build github.com/creack/docker-firefox
  41. This will clone the Github repository and use it as context. The
  42. ``Dockerfile`` at the root of the repository is used as
  43. ``Dockerfile``. Note that you can specify an arbitrary git repository
  44. by using the ``git://`` schema.