build.rst 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. -rm: Remove intermediate containers after a successful build
  14. 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
  15. Examples
  16. --------
  17. .. code-block:: bash
  18. sudo docker build .
  19. This will read the ``Dockerfile`` from the current directory. It will
  20. also send any other files and directories found in the current
  21. directory to the ``docker`` daemon.
  22. The contents of this directory would be used by ``ADD`` commands found
  23. within the ``Dockerfile``. This will send a lot of data to the
  24. ``docker`` daemon if the current directory contains a lot of data. If
  25. the absolute path is provided instead of ``.`` then only the files and
  26. directories required by the ADD commands from the ``Dockerfile`` will be
  27. added to the context and transferred to the ``docker`` daemon.
  28. .. code-block:: bash
  29. sudo docker build -t vieux/apache:2.0 .
  30. This will build like the previous example, but it will then tag the
  31. resulting image. The repository name will be ``vieux/apache`` and the
  32. tag will be ``2.0``
  33. .. code-block:: bash
  34. sudo docker build - < Dockerfile
  35. This will read a ``Dockerfile`` from *stdin* without context. Due to
  36. the lack of a context, no contents of any local directory will be sent
  37. to the ``docker`` daemon. ``ADD`` doesn't work when running in this
  38. mode because the absence of the context provides no source files to
  39. copy to the container.
  40. .. code-block:: bash
  41. sudo docker build github.com/creack/docker-firefox
  42. This will clone the Github repository and use it as context. The
  43. ``Dockerfile`` at the root of the repository is used as
  44. ``Dockerfile``. Note that you can specify an arbitrary git repository
  45. by using the ``git://`` schema.