github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/cli/man/docker-build.1.md (about)

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