|
@@ -15,27 +15,39 @@ commit them along the way, giving you a final image.
|
|
|
|
|
|
.. contents:: Table of Contents
|
|
|
|
|
|
+.. _dockerfile_usage:
|
|
|
+
|
|
|
1. Usage
|
|
|
========
|
|
|
|
|
|
-To build an image from a source repository, create a description file
|
|
|
-called ``Dockerfile`` at the root of your repository. This file will
|
|
|
-describe the steps to assemble the image.
|
|
|
+To :ref:`build <cli_build>` an image from a source repository, create
|
|
|
+a description file called ``Dockerfile`` at the root of your
|
|
|
+repository. This file will describe the steps to assemble the image.
|
|
|
|
|
|
Then call ``docker build`` with the path of your source repository as
|
|
|
-argument:
|
|
|
+argument (for example, ``.``):
|
|
|
|
|
|
``sudo docker build .``
|
|
|
|
|
|
+The path to the source repository defines where to find the *context*
|
|
|
+of the build. The build is run by the Docker daemon, not by the CLI,
|
|
|
+so the whole context must be transferred to the daemon. The Docker CLI
|
|
|
+reports "Uploading context" when the context is sent to the daemon.
|
|
|
+
|
|
|
You can specify a repository and tag at which to save the new image if the
|
|
|
build succeeds:
|
|
|
|
|
|
``sudo docker build -t shykes/myapp .``
|
|
|
|
|
|
-Docker will run your steps one-by-one, committing the result if necessary,
|
|
|
-before finally outputting the ID of your new image.
|
|
|
+The Docker daemon will run your steps one-by-one, committing the
|
|
|
+result if necessary, before finally outputting the ID of your new
|
|
|
+image. The Docker daemon will automatically clean up the context you
|
|
|
+sent.
|
|
|
|
|
|
-When you're done with your build, you're ready to look into :ref:`image_push`.
|
|
|
+When you're done with your build, you're ready to look into
|
|
|
+:ref:`image_push`.
|
|
|
+
|
|
|
+.. _dockerfile_format:
|
|
|
|
|
|
2. Format
|
|
|
=========
|
|
@@ -63,12 +75,16 @@ allows statements like:
|
|
|
# Comment
|
|
|
RUN echo 'we are running some # of cool things'
|
|
|
|
|
|
+.. _dockerfile_instructions:
|
|
|
+
|
|
|
3. Instructions
|
|
|
===============
|
|
|
|
|
|
Here is the set of instructions you can use in a ``Dockerfile`` for
|
|
|
building images.
|
|
|
|
|
|
+.. _dockerfile_from:
|
|
|
+
|
|
|
3.1 FROM
|
|
|
--------
|
|
|
|
|
@@ -94,6 +110,8 @@ output by the commit before each new ``FROM`` command.
|
|
|
If no ``tag`` is given to the ``FROM`` instruction, ``latest`` is
|
|
|
assumed. If the used tag does not exist, an error will be returned.
|
|
|
|
|
|
+.. _dockerfile_maintainer:
|
|
|
+
|
|
|
3.2 MAINTAINER
|
|
|
--------------
|
|
|
|
|
@@ -102,6 +120,8 @@ assumed. If the used tag does not exist, an error will be returned.
|
|
|
The ``MAINTAINER`` instruction allows you to set the *Author* field of
|
|
|
the generated images.
|
|
|
|
|
|
+.. _dockerfile_run:
|
|
|
+
|
|
|
3.3 RUN
|
|
|
-------
|
|
|
|
|
@@ -124,7 +144,7 @@ Known Issues (RUN)
|
|
|
``rm`` a file, for example. The issue describes a workaround.
|
|
|
* :issue:`2424` Locale will not be set automatically.
|
|
|
|
|
|
-
|
|
|
+.. _dockerfile_cmd:
|
|
|
|
|
|
3.4 CMD
|
|
|
-------
|
|
@@ -169,7 +189,7 @@ array:
|
|
|
|
|
|
If you would like your container to run the same executable every
|
|
|
time, then you should consider using ``ENTRYPOINT`` in combination
|
|
|
-with ``CMD``. See :ref:`entrypoint_def`.
|
|
|
+with ``CMD``. See :ref:`dockerfile_entrypoint`.
|
|
|
|
|
|
If the user specifies arguments to ``docker run`` then they will
|
|
|
override the default specified in CMD.
|
|
@@ -179,6 +199,8 @@ override the default specified in CMD.
|
|
|
command and commits the result; ``CMD`` does not execute anything at
|
|
|
build time, but specifies the intended command for the image.
|
|
|
|
|
|
+.. _dockerfile_expose:
|
|
|
+
|
|
|
3.5 EXPOSE
|
|
|
----------
|
|
|
|
|
@@ -189,6 +211,8 @@ functionally equivalent to running ``docker commit -run '{"PortSpecs":
|
|
|
["<port>", "<port2>"]}'`` outside the builder. Refer to
|
|
|
:ref:`port_redirection` for detailed information.
|
|
|
|
|
|
+.. _dockerfile_env:
|
|
|
+
|
|
|
3.6 ENV
|
|
|
-------
|
|
|
|
|
@@ -203,6 +227,8 @@ with ``<key>=<value>``
|
|
|
The environment variables will persist when a container is run
|
|
|
from the resulting image.
|
|
|
|
|
|
+.. _dockerfile_add:
|
|
|
+
|
|
|
3.7 ADD
|
|
|
-------
|
|
|
|
|
@@ -263,7 +289,7 @@ The copy obeys the following rules:
|
|
|
* If ``<dest>`` doesn't exist, it is created along with all missing
|
|
|
directories in its path.
|
|
|
|
|
|
-.. _entrypoint_def:
|
|
|
+.. _dockerfile_entrypoint:
|
|
|
|
|
|
3.8 ENTRYPOINT
|
|
|
--------------
|
|
@@ -312,6 +338,7 @@ this optional but default, you could use a CMD:
|
|
|
CMD ["-l", "-"]
|
|
|
ENTRYPOINT ["/usr/bin/wc"]
|
|
|
|
|
|
+.. _dockerfile_volume:
|
|
|
|
|
|
3.9 VOLUME
|
|
|
----------
|
|
@@ -322,6 +349,8 @@ The ``VOLUME`` instruction will create a mount point with the specified name and
|
|
|
as holding externally mounted volumes from native host or other containers. For more information/examples
|
|
|
and mounting instructions via docker client, refer to :ref:`volume_def` documentation.
|
|
|
|
|
|
+.. _dockerfile_user:
|
|
|
+
|
|
|
3.10 USER
|
|
|
---------
|
|
|
|
|
@@ -330,6 +359,8 @@ and mounting instructions via docker client, refer to :ref:`volume_def` document
|
|
|
The ``USER`` instruction sets the username or UID to use when running
|
|
|
the image.
|
|
|
|
|
|
+.. _dockerfile_workdir:
|
|
|
+
|
|
|
3.11 WORKDIR
|
|
|
------------
|
|
|
|
|
@@ -338,6 +369,7 @@ the image.
|
|
|
The ``WORKDIR`` instruction sets the working directory in which
|
|
|
the command given by ``CMD`` is executed.
|
|
|
|
|
|
+.. _dockerfile_examples:
|
|
|
|
|
|
4. Dockerfile Examples
|
|
|
======================
|