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