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