2013-05-21 11:47:16 -06:00
|
|
|
:title: Build Command
|
|
|
|
:description: Build a new image from the Dockerfile passed via stdin
|
|
|
|
:keywords: build, docker, container, documentation
|
|
|
|
|
2013-05-29 11:53:44 -07:00
|
|
|
================================================
|
|
|
|
``build`` -- Build a container from a Dockerfile
|
|
|
|
================================================
|
2013-05-01 13:37:32 -07:00
|
|
|
|
|
|
|
::
|
|
|
|
|
2013-06-06 16:48:36 -07:00
|
|
|
Usage: docker build [OPTIONS] PATH | URL | -
|
2013-05-30 12:35:19 -07:00
|
|
|
Build a new container image from the source code at PATH
|
2013-07-31 15:32:08 +00:00
|
|
|
-t="": Repository name (and optionally a tag) to be applied to the resulting image in case of success.
|
2013-07-11 15:12:25 -09:00
|
|
|
-q=false: Suppress verbose build output.
|
2013-08-02 16:18:54 +00:00
|
|
|
-no-cache: Do not use the cache when building the image.
|
2013-09-10 18:39:47 +00:00
|
|
|
-rm: Remove intermediate containers after a successful build
|
2013-06-10 09:32:31 -07:00
|
|
|
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
|
2013-06-06 16:48:36 -07:00
|
|
|
|
2013-05-29 11:50:49 -07:00
|
|
|
|
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2013-08-13 18:05:35 -07:00
|
|
|
sudo docker build .
|
2013-05-29 11:50:49 -07:00
|
|
|
|
2013-08-13 18:05:35 -07:00
|
|
|
This will read the ``Dockerfile`` from the current directory. It will
|
|
|
|
also send any other files and directories found in the current
|
|
|
|
directory to the ``docker`` daemon.
|
|
|
|
|
|
|
|
The contents of this directory would be used by ``ADD`` commands found
|
|
|
|
within the ``Dockerfile``. This will send a lot of data to the
|
|
|
|
``docker`` daemon if the current directory contains a lot of data. If
|
|
|
|
the absolute path is provided instead of ``.`` then only the files and
|
|
|
|
directories required by the ADD commands from the ``Dockerfile`` will be
|
|
|
|
added to the context and transferred to the ``docker`` daemon.
|
2013-05-29 11:50:49 -07:00
|
|
|
|
2013-08-05 11:07:27 +00:00
|
|
|
.. code-block:: bash
|
|
|
|
|
2013-08-13 18:05:35 -07:00
|
|
|
sudo docker build -t vieux/apache:2.0 .
|
2013-08-05 11:07:27 +00:00
|
|
|
|
2013-08-13 18:05:35 -07:00
|
|
|
This will build like the previous example, but it will then tag the
|
|
|
|
resulting image. The repository name will be ``vieux/apache`` and the
|
|
|
|
tag will be ``2.0``
|
2013-08-05 11:07:27 +00:00
|
|
|
|
|
|
|
|
2013-05-29 11:50:49 -07:00
|
|
|
.. code-block:: bash
|
|
|
|
|
2013-08-13 18:05:35 -07:00
|
|
|
sudo docker build - < Dockerfile
|
2013-05-29 11:50:49 -07:00
|
|
|
|
2013-08-13 18:05:35 -07:00
|
|
|
This will read a ``Dockerfile`` from *stdin* without context. Due to
|
|
|
|
the lack of a context, no contents of any local directory will be sent
|
|
|
|
to the ``docker`` daemon. ``ADD`` doesn't work when running in this
|
|
|
|
mode because the absence of the context provides no source files to
|
|
|
|
copy to the container.
|
2013-06-18 14:36:35 -07:00
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2013-08-13 18:05:35 -07:00
|
|
|
sudo docker build github.com/creack/docker-firefox
|
2013-06-18 14:36:35 -07:00
|
|
|
|
2013-08-13 18:05:35 -07:00
|
|
|
This will clone the Github repository and use it as context. The
|
|
|
|
``Dockerfile`` at the root of the repository is used as
|
|
|
|
``Dockerfile``. Note that you can specify an arbitrary git repository
|
|
|
|
by using the ``git://`` schema.
|