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