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