github.com/stchris/docker@v1.4.2-0.20150106053530-1510a324dbd5/docs/man/docker-build.1.md (about)

     1  % DOCKER(1) Docker User Manuals
     2  % Docker Community
     3  % JUNE 2014
     4  # NAME
     5  docker-build - Build a new image from the source code at PATH
     6  
     7  # SYNOPSIS
     8  **docker build**
     9  [**--force-rm**[=*false*]]
    10  [**--no-cache**[=*false*]]
    11  [**-q**|**--quiet**[=*false*]]
    12  [**--rm**[=*true*]]
    13  [**-t**|**--tag**[=*TAG*]]
    14  PATH | URL | -
    15  
    16  # DESCRIPTION
    17  This will read the Dockerfile from the directory specified in **PATH**.
    18  It also sends any other files and directories found in the current
    19  directory to the Docker daemon. The contents of this directory would
    20  be used by **ADD** commands found within the Dockerfile.
    21  
    22  Warning, this will send a lot of data to the Docker daemon depending
    23  on the contents of the current directory. The build is run by the Docker 
    24  daemon, not by the CLI, so the whole context must be transferred to the daemon. 
    25  The Docker CLI reports "Sending build context to Docker daemon" when the context is sent to 
    26  the daemon.
    27  
    28  When a single Dockerfile is given as the URL, then no context is set.
    29  When a Git repository is set as the **URL**, the repository is used
    30  as context.
    31  
    32  # OPTIONS
    33  **--force-rm**=*true*|*false*
    34     Always remove intermediate containers, even after unsuccessful builds. The default is *false*.
    35  
    36  **--no-cache**=*true*|*false*
    37     Do not use cache when building the image. The default is *false*.
    38  
    39  **-q**, **--quiet**=*true*|*false*
    40     Suppress the verbose output generated by the containers. The default is *false*.
    41  
    42  **--rm**=*true*|*false*
    43     Remove intermediate containers after a successful build. The default is *true*.
    44  
    45  **-t**, **--tag**=""
    46     Repository name (and optionally a tag) to be applied to the resulting image in case of success
    47  
    48  # EXAMPLES
    49  
    50  ## Building an image using a Dockefile located inside the current directory
    51  
    52  Docker images can be built using the build command and a Dockerfile:
    53  
    54      docker build .
    55  
    56  During the build process Docker creates intermediate images. In order to
    57  keep them, you must explicitly set `--rm=false`.
    58  
    59      docker build --rm=false .
    60  
    61  A good practice is to make a sub-directory with a related name and create
    62  the Dockerfile in that directory. For example, a directory called mongo may
    63  contain a Dockerfile to create a Docker MongoDB image. Likewise, another
    64  directory called httpd may be used to store Dockerfiles for Apache web
    65  server images.
    66  
    67  It is also a good practice to add the files required for the image to the
    68  sub-directory. These files will then be specified with the `COPY` or `ADD`
    69  instructions in the `Dockerfile`.
    70  
    71  Note: If you include a tar file (a good practice), then Docker will
    72  automatically extract the contents of the tar file specified within the `ADD`
    73  instruction into the specified target.
    74  
    75  ## Building an image and naming that image
    76  
    77  A good practice is to give a name to the image you are building. There are
    78  no hard rules here but it is best to give the names consideration. 
    79  
    80  The **-t**/**--tag** flag is used to rename an image. Here are some examples:
    81  
    82  Though it is not a good practice, image names can be arbtrary:
    83  
    84      docker build -t myimage .
    85  
    86  A better approach is to provide a fully qualified and meaningful repository,
    87  name, and tag (where the tag in this context means the qualifier after 
    88  the ":"). In this example we build a JBoss image for the Fedora repository 
    89  and give it the version 1.0:
    90  
    91      docker build -t fedora/jboss:1.0
    92  
    93  The next example is for the "whenry" user repository and uses Fedora and
    94  JBoss and gives it the version 2.1 :
    95  
    96      docker build -t whenry/fedora-jboss:V2.1
    97  
    98  If you do not provide a version tag then Docker will assign `latest`:
    99  
   100      docker build -t whenry/fedora-jboss
   101  
   102  When you list the images, the image above will have the tag `latest`.
   103  
   104  So renaming an image is arbitrary but consideration should be given to 
   105  a useful convention that makes sense for consumers and should also take
   106  into account Docker community conventions.
   107  
   108  
   109  ## Building an image using a URL
   110  
   111  This will clone the specified Github repository from the URL and use it
   112  as context. The Dockerfile at the root of the repository is used as
   113  Dockerfile. This only works if the Github repository is a dedicated
   114  repository.
   115  
   116      docker build github.com/scollier/Fedora-Dockerfiles/tree/master/apache
   117  
   118  Note: You can set an arbitrary Git repository via the `git://` schema.
   119  
   120  # HISTORY
   121  March 2014, Originally compiled by William Henry (whenry at redhat dot com)
   122  based on docker.com source material and internal work.
   123  June 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>