github.com/walkingsparrow/docker@v1.4.2-0.20151218153551-b708a2249bfa/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  [**--build-arg**[=*[]*]]
    10  [**--cpu-shares**[=*0*]]
    11  [**--cgroup-parent**[=*CGROUP-PARENT*]]
    12  [**--help**]
    13  [**-f**|**--file**[=*PATH/Dockerfile*]]
    14  [**--force-rm**[=*false*]]
    15  [**--isolation**[=*default*]]
    16  [**--no-cache**[=*false*]]
    17  [**--pull**[=*false*]]
    18  [**-q**|**--quiet**[=*false*]]
    19  [**--rm**[=*true*]]
    20  [**-t**|**--tag**[=*[]*]]
    21  [**-m**|**--memory**[=*MEMORY*]]
    22  [**--memory-swap**[=*MEMORY-SWAP*]]
    23  [**--shm-size**[=*SHM-SIZE*]]
    24  [**--cpu-period**[=*0*]]
    25  [**--cpu-quota**[=*0*]]
    26  [**--cpuset-cpus**[=*CPUSET-CPUS*]]
    27  [**--cpuset-mems**[=*CPUSET-MEMS*]]
    28  [**--ulimit**[=*[]*]]
    29  PATH | URL | -
    30  
    31  # DESCRIPTION
    32  This will read the Dockerfile from the directory specified in **PATH**.
    33  It also sends any other files and directories found in the current
    34  directory to the Docker daemon. The contents of this directory would
    35  be used by **ADD** commands found within the Dockerfile.
    36  
    37  Warning, this will send a lot of data to the Docker daemon depending
    38  on the contents of the current directory. The build is run by the Docker
    39  daemon, not by the CLI, so the whole context must be transferred to the daemon. 
    40  The Docker CLI reports "Sending build context to Docker daemon" when the context is sent to
    41  the daemon.
    42  
    43  When the URL to a tarball archive or to a single Dockerfile is given, no context is sent from
    44  the client to the Docker daemon. In this case, the Dockerfile at the root of the archive and
    45  the rest of the archive will get used as the context of the build.  When a Git repository is
    46  set as the **URL**, the repository is cloned locally and then sent as the context.
    47  
    48  # OPTIONS
    49  **-f**, **--file**=*PATH/Dockerfile*
    50     Path to the Dockerfile to use. If the path is a relative path and you are
    51     building from a local directory, then the path must be relative to that
    52     directory. If you are building from a remote URL pointing to either a
    53     tarball or a Git repository, then the path must be relative to the root of
    54     the remote context. In all cases, the file must be within the build context.
    55     The default is *Dockerfile*.
    56  
    57  **--build-arg**=*variable*
    58     name and value of a **buildarg**.
    59  
    60     For example, if you want to pass a value for `http_proxy`, use
    61     `--build-arg=http_proxy="http://some.proxy.url"`
    62  
    63     Users pass these values at build-time. Docker uses the `buildargs` as the
    64     environment context for command(s) run via the Dockerfile's `RUN` instruction
    65     or for variable expansion in other Dockerfile instructions. This is not meant
    66     for passing secret values. [Read more about the buildargs instruction](/reference/builder/#arg)
    67  
    68  **--force-rm**=*true*|*false*
    69     Always remove intermediate containers, even after unsuccessful builds. The default is *false*.
    70  
    71  **--isolation**="*default*"
    72     Isolation specifies the type of isolation technology used by containers. 
    73  
    74  **--no-cache**=*true*|*false*
    75     Do not use cache when building the image. The default is *false*.
    76  
    77  **--help**
    78    Print usage statement
    79  
    80  **--pull**=*true*|*false*
    81     Always attempt to pull a newer version of the image. The default is *false*.
    82  
    83  **-q**, **--quiet**=*true*|*false*
    84     Suppress the verbose output generated by the containers. The default is *false*.
    85  
    86  **--rm**=*true*|*false*
    87     Remove intermediate containers after a successful build. The default is *true*.
    88  
    89  **-t**, **--tag**=""
    90     Repository names (and optionally with tags) to be applied to the resulting image in case of success.
    91  
    92  **-m**, **--memory**=*MEMORY*
    93    Memory limit
    94  
    95  **--memory-swap**=*MEMORY-SWAP*
    96    Total memory (memory + swap), '-1' to disable swap.
    97  
    98  **--shm-size**=*SHM-SIZE*
    99    Size of `/dev/shm`. The format is `<number><unit>`. `number` must be greater than `0`.
   100    Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you omit the unit, the system uses bytes.
   101    If you omit the size entirely, the system uses `64m`.
   102  
   103  **--cpu-shares**=*0*
   104    CPU shares (relative weight).
   105  
   106    By default, all containers get the same proportion of CPU cycles.
   107    CPU shares is a 'relative weight', relative to the default setting of 1024.
   108    This default value is defined here: 
   109    ```
   110     cat /sys/fs/cgroup/cpu/cpu.shares
   111     1024
   112    ```
   113    You can change this proportion by adjusting the container's CPU share 
   114    weighting relative to the weighting of all other running containers.
   115  
   116    To modify the proportion from the default of 1024, use the **--cpu-shares**
   117    flag to set the weighting to 2 or higher.
   118  
   119        Container   CPU share    Flag             
   120        {C0}        60% of CPU  --cpu-shares=614 (614 is 60% of 1024)
   121        {C1}        40% of CPU  --cpu-shares=410 (410 is 40% of 1024)
   122  
   123    The proportion is only applied when CPU-intensive processes are running.
   124    When tasks in one container are idle, the other containers can use the
   125    left-over CPU time. The actual amount of CPU time used varies depending on
   126    the number of containers running on the system.
   127  
   128    For example, consider three containers, where one has **--cpu-shares=1024** and
   129    two others have **--cpu-shares=512**. When processes in all three
   130    containers attempt to use 100% of CPU, the first container would receive
   131    50% of the total CPU time. If you add a fourth container with **--cpu-shares=1024**,
   132    the first container only gets 33% of the CPU. The remaining containers
   133    receive 16.5%, 16.5% and 33% of the CPU.
   134  
   135  
   136        Container   CPU share   Flag                CPU time            
   137        {C0}        100%        --cpu-shares=1024   33%
   138        {C1}        50%         --cpu-shares=512    16.5%
   139        {C2}        50%         --cpu-shares=512    16.5%
   140        {C4}        100%        --cpu-shares=1024   33%
   141  
   142  
   143    On a multi-core system, the shares of CPU time are distributed across the CPU
   144    cores. Even if a container is limited to less than 100% of CPU time, it can
   145    use 100% of each individual CPU core.
   146  
   147    For example, consider a system with more than three cores. If you start one
   148    container **{C0}** with **--cpu-shares=512** running one process, and another container
   149    **{C1}** with **--cpu-shares=1024** running two processes, this can result in the following
   150    division of CPU shares:
   151  
   152        PID    container    CPU    CPU share
   153        100    {C0}         0      100% of CPU0
   154        101    {C1}         1      100% of CPU1
   155        102    {C1}         2      100% of CPU2
   156  
   157  **--cpu-period**=*0*
   158    Limit the CPU CFS (Completely Fair Scheduler) period.
   159  
   160    Limit the container's CPU usage. This flag causes the kernel to restrict the
   161    container's CPU usage to the period you specify.
   162  
   163  **--cpu-quota**=*0*
   164    Limit the CPU CFS (Completely Fair Scheduler) quota. 
   165  
   166    By default, containers run with the full CPU resource. This flag causes the
   167  kernel to restrict the container's CPU usage to the quota you specify.
   168  
   169  **--cpuset-cpus**=*CPUSET-CPUS*
   170    CPUs in which to allow execution (0-3, 0,1).
   171  
   172  **--cpuset-mems**=*CPUSET-MEMS*
   173    Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on
   174    NUMA systems.
   175  
   176    For example, if you have four memory nodes on your system (0-3), use `--cpuset-mems=0,1`
   177  to ensure the processes in your Docker container only use memory from the first
   178  two memory nodes.
   179  
   180  **--cgroup-parent**=*CGROUP-PARENT*
   181    Path to `cgroups` under which the container's `cgroup` are created.
   182  
   183    If the path is not absolute, the path is considered relative to the `cgroups` path of the init process.
   184  Cgroups are created if they do not already exist.
   185  
   186  **--ulimit**=[]
   187    Ulimit options
   188  
   189    For more information about `ulimit` see [Setting ulimits in a 
   190  container](https://docs.docker.com/reference/commandline/run/#setting-ulimits-in-a-container)
   191  
   192  # EXAMPLES
   193  
   194  ## Building an image using a Dockerfile located inside the current directory
   195  
   196  Docker images can be built using the build command and a Dockerfile:
   197  
   198      docker build .
   199  
   200  During the build process Docker creates intermediate images. In order to
   201  keep them, you must explicitly set `--rm=false`.
   202  
   203      docker build --rm=false .
   204  
   205  A good practice is to make a sub-directory with a related name and create
   206  the Dockerfile in that directory. For example, a directory called mongo may
   207  contain a Dockerfile to create a Docker MongoDB image. Likewise, another
   208  directory called httpd may be used to store Dockerfiles for Apache web
   209  server images.
   210  
   211  It is also a good practice to add the files required for the image to the
   212  sub-directory. These files will then be specified with the `COPY` or `ADD`
   213  instructions in the `Dockerfile`.
   214  
   215  Note: If you include a tar file (a good practice), then Docker will
   216  automatically extract the contents of the tar file specified within the `ADD`
   217  instruction into the specified target.
   218  
   219  ## Building an image and naming that image
   220  
   221  A good practice is to give a name to the image you are building. Note that 
   222  only a-z0-9-_. should be used for consistency.  There are no hard rules here but it is best to give the names consideration. 
   223  
   224  The **-t**/**--tag** flag is used to rename an image. Here are some examples:
   225  
   226  Though it is not a good practice, image names can be arbitrary:
   227  
   228      docker build -t myimage .
   229  
   230  A better approach is to provide a fully qualified and meaningful repository,
   231  name, and tag (where the tag in this context means the qualifier after 
   232  the ":"). In this example we build a JBoss image for the Fedora repository 
   233  and give it the version 1.0:
   234  
   235      docker build -t fedora/jboss:1.0 .
   236  
   237  The next example is for the "whenry" user repository and uses Fedora and
   238  JBoss and gives it the version 2.1 :
   239  
   240      docker build -t whenry/fedora-jboss:v2.1 .
   241  
   242  If you do not provide a version tag then Docker will assign `latest`:
   243  
   244      docker build -t whenry/fedora-jboss .
   245  
   246  When you list the images, the image above will have the tag `latest`.
   247  
   248  You can apply multiple tags to an image. For example, you can apply the `latest`
   249  tag to a newly built image and add another tag that references a specific
   250  version.
   251  For example, to tag an image both as `whenry/fedora-jboss:latest` and
   252  `whenry/fedora-jboss:v2.1`, use the following:
   253  
   254      docker build -t whenry/fedora-jboss:latest -t whenry/fedora-jboss:v2.1 .
   255  
   256  So renaming an image is arbitrary but consideration should be given to 
   257  a useful convention that makes sense for consumers and should also take
   258  into account Docker community conventions.
   259  
   260  
   261  ## Building an image using a URL
   262  
   263  This will clone the specified GitHub repository from the URL and use it
   264  as context. The Dockerfile at the root of the repository is used as
   265  Dockerfile. This only works if the GitHub repository is a dedicated
   266  repository.
   267  
   268      docker build github.com/scollier/purpletest
   269  
   270  Note: You can set an arbitrary Git repository via the `git://` schema.
   271  
   272  ## Building an image using a URL to a tarball'ed context
   273  
   274  This will send the URL itself to the Docker daemon. The daemon will fetch the
   275  tarball archive, decompress it and use its contents as the build context.  The 
   276  Dockerfile at the root of the archive and the rest of the archive will get used
   277  as the context of the build. If you pass an **-f PATH/Dockerfile** option as well,
   278  the system will look for that file inside the contents of the tarball.
   279  
   280      docker build -f dev/Dockerfile https://10.10.10.1/docker/context.tar.gz
   281  
   282  Note: supported compression formats are 'xz', 'bzip2', 'gzip' and 'identity' (no compression).
   283  
   284  ## Specify isolation technology for container (--isolation)
   285  
   286  This option is useful in situations where you are running Docker containers on
   287  Windows. The `--isolation=<value>` option sets a container's isolation
   288  technology. On Linux, the only supported is the `default` option which uses
   289  Linux namespaces. On Microsoft Windows, you can specify these values:
   290  
   291  * `default`: Use the value specified by the Docker daemon's `--exec-opt` . If the `daemon` does not specify an isolation technology, Microsoft Windows uses `process` as its default value.
   292  * `process`: Namespace isolation only.
   293  * `hyperv`: Hyper-V hypervisor partition-based isolation.
   294  
   295  Specifying the `--isolation` flag without a value is the same as setting `--isolation="default"`.
   296  
   297  # HISTORY
   298  March 2014, Originally compiled by William Henry (whenry at redhat dot com)
   299  based on docker.com source material and internal work.
   300  June 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
   301  June 2015, updated by Sally O'Malley <somalley@redhat.com>