1DOCKER(1)(Docker)                                            DOCKER(1)(Docker)
2
3
4
5Docker Community JUNE 2014
6
7

NAME

9       docker-build - Build an image from a Dockerfile
10
11
12

SYNOPSIS

14       docker  build  [--add-host[=[]]] [--build-arg[=[]]] [--cache-from[=[]]]
15       [--cpu-shares[=0]] [--cgroup-parent[=CGROUP-PARENT]]  [--help]  [--iid‐
16       file[=CIDFILE]]  [-f|--file[=PATH/Dockerfile]]  [-squash]  Experimental
17       [--force-rm]   [--isolation[=default]]   [--label[=[]]]    [--no-cache]
18       [--pull]   [--compress]   [-q|--quiet]   [--rm[=true]]  [-t|--tag[=[]]]
19       [-m|--memory[=MEMORY]] [--memory-swap[=LIMIT]]  [--network[="default"]]
20       [--shm-size[=SHM-SIZE]]       [--cpu-period[=0]]      [--cpu-quota[=0]]
21       [--cpuset-cpus[=CPUSET-CPUS]]   [--cpuset-mems[=CPUSET-MEMS]]   [--tar‐
22       get[=[]]] [--ulimit[=[]]] PATH | URL | -
23
24
25

DESCRIPTION

27       This will read the Dockerfile from the directory specified in PATH.  It
28       also sends any other files and directories found in the current  direc‐
29       tory to the Docker daemon. The contents of this directory would be used
30       by ADD commands found within the Dockerfile.
31
32
33       Warning, this will send a lot of data to the Docker daemon depending on
34       the  contents  of the current directory. The build is run by the Docker
35       daemon, not by the CLI, so the whole context must be transferred to the
36       daemon.   The  Docker CLI reports "Sending build context to Docker dae‐
37       mon" when the context is sent to the daemon.
38
39
40       When the URL to a tarball archive or to a single Dockerfile  is  given,
41       no  context is sent from the client to the Docker daemon. In this case,
42       the Dockerfile at the root of the archive and the rest of  the  archive
43       will  get  used  as the context of the build.  When a Git repository is
44       set as the URL, the repository is cloned locally and then sent  as  the
45       context.
46
47
48

OPTIONS

50       -f, --file=PATH/Dockerfile
51          Path  to  the  Dockerfile to use. If the path is a relative path and
52       you are
53          building from a local directory, then the path must be  relative  to
54       that
55          directory.  If you are building from a remote URL pointing to either
56       a
57          tarball or a Git repository, then the path must be relative  to  the
58       root of
59          the  remote context. In all cases, the file must be within the build
60       context.
61          The default is Dockerfile.
62
63
64       --squash=true|false
65          Experimental Only
66          Once the image is built, squash the new layers into a new image with
67       a single
68          new  layer. Squashing does not destroy any existing image, rather it
69       creates a new
70          image with the content of  the  squashed  layers.  This  effectively
71       makes it look
72          like  all  Dockerfile commands were created with a single layer. The
73       build
74          cache is preserved with this method.
75
76
77       Note: using this option means the new image will not be able to take
78          advantage of layer sharing with other images and  may  use  signifi‐
79       cantly more
80          space.
81
82
83       Note:  using  this option you may see significantly more space used due
84       to
85          storing two copies of the image, one for the build  cache  with  all
86       the cache
87          layers in tact, and one for the squashed version.
88
89
90       --add-host=[]
91          Add a custom host-to-IP mapping (host:ip)
92
93
94       Add  a  line  to /etc/hosts. The format is hostname:ip.  The --add-host
95       option can be set multiple times.
96
97
98       --build-arg=variable
99          name and value of a buildarg.
100
101
102       For example, if you want to pass a value for http_proxy, use
103          --build-arg=http_proxy="http://some.proxy.url"
104
105
106       Users pass these values at build-time. Docker uses the buildargs as the
107          environment context for command(s)  run  via  the  Dockerfile's  RUN
108       instruction
109          or  for variable expansion in other Dockerfile instructions. This is
110       not meant
111          for passing secret values. Read more about the buildargs instruction
112https://docs.docker.com/engine/reference/builder/#arg⟩
113
114
115       --cache-from=""
116          Set image that will be used as a build cache source.
117
118
119       --force-rm=true|false
120          Always  remove  intermediate  containers,  even  after  unsuccessful
121       builds. The default is false.
122
123
124       --isolation="default"
125          Isolation specifies the type of isolation technology  used  by  con‐
126       tainers.
127
128
129       --label=label
130          Set metadata for an image
131
132
133       --no-cache=true|false
134          Do not use cache when building the image. The default is false.
135
136
137       --iidfile=""
138          Write the image ID to the file
139
140
141       --help
142         Print usage statement
143
144
145       --pull=true|false
146          Always  attempt to pull a newer version of the image. The default is
147       false.
148
149
150       --compress=true|false
151           Compress the build context using gzip. The default is false.
152
153
154       -q, --quiet=true|false
155          Suppress the build output and print image ID on success. The default
156       is false.
157
158
159       --rm=true|false
160          Remove intermediate containers after a successful build. The default
161       is true.
162
163
164       -t, --tag=""
165          Repository names (and optionally with tags) to  be  applied  to  the
166       resulting
167          image  in  case of success. Refer to docker-tag(1) for more informa‐
168       tion
169          about valid tag names.
170
171
172       -m, --memory=MEMORY
173         Memory limit
174
175
176       --memory-swap=LIMIT
177          A limit value equal to memory plus swap. Must be used with  the   -m
178       (--memory) flag. The swap LIMIT should always be larger than -m (--mem‐
179       ory) value.
180
181
182       The format of LIMIT is <number>[<unit>].  Unit  can  be  b  (bytes),  k
183       (kilobytes),  m  (megabytes),  or g (gigabytes). If you don't specify a
184       unit, b is used. Set LIMIT to -1 to enable unlimited swap.
185
186
187       --network=bridge
188         Set the networking mode for the RUN instructions during  build.  Sup‐
189       ported standard
190         values  are:  bridge,  host,  none and container:<name|id>. Any other
191       value
192         is taken as a custom network's name or ID which this container should
193       connect to.
194
195
196       --shm-size=SHM-SIZE
197         Size  of  /dev/shm.  The  format  is  <number><unit>.  number must be
198       greater than 0.
199         Unit is optional and can be b (bytes), k (kilobytes), m  (megabytes),
200       or g (gigabytes). If you omit the unit, the system uses bytes.
201         If you omit the size entirely, the system uses 64m.
202
203
204       --cpu-shares=0
205         CPU shares (relative weight).
206
207
208       By default, all containers get the same proportion of CPU cycles.
209         CPU shares is a 'relative weight', relative to the default setting of
210       1024.
211         This default value is defined here:
212
213
214                 cat /sys/fs/cgroup/cpu/cpu.shares
215                 1024
216
217
218
219       You can change this proportion by adjusting the container's CPU share
220         weighting relative to the weighting of all other running containers.
221
222
223       To modify the proportion from the default of 1024, use the --cpu-shares
224         flag to set the weighting to 2 or higher.
225
226
227                Container   CPU share    Flag
228                {C0}        60% of CPU  --cpu-shares=614 (614 is 60% of 1024)
229                {C1}        40% of CPU  --cpu-shares=410 (410 is 40% of 1024)
230
231
232
233       The proportion is only applied when CPU-intensive  processes  are  run‐
234       ning.
235         When  tasks  in  one container are idle, the other containers can use
236       the
237         left-over CPU time. The actual amount of CPU time used varies depend‐
238       ing on
239         the number of containers running on the system.
240
241
242       For example, consider three containers, where one has --cpu-shares=1024
243       and
244         two others have --cpu-shares=512. When processes in all three
245         containers attempt to use 100% of  CPU,  the  first  container  would
246       receive
247         50%  of  the  total  CPU  time.  If  you  add a fourth container with
248       --cpu-shares=1024,
249         the first container only gets 33% of the CPU. The remaining  contain‐
250       ers
251         receive 16.5%, 16.5% and 33% of the CPU.
252
253
254                Container   CPU share   Flag                CPU time
255                {C0}        100%        --cpu-shares=1024   33%
256                {C1}        50%         --cpu-shares=512    16.5%
257                {C2}        50%         --cpu-shares=512    16.5%
258                {C4}        100%        --cpu-shares=1024   33%
259
260
261
262       On  a  multi-core system, the shares of CPU time are distributed across
263       the CPU
264         cores. Even if a container is limited to less than 100% of CPU  time,
265       it can
266         use 100% of each individual CPU core.
267
268
269       For example, consider a system with more than three cores. If you start
270       one
271         container {C0} with --cpu-shares=512 running one process, and another
272       container
273         {C1} with --cpu-shares=1024 running two processes, this can result in
274       the following
275         division of CPU shares:
276
277
278                PID    container    CPU    CPU share
279                100    {C0}         0      100% of CPU0
280                101    {C1}         1      100% of CPU1
281                102    {C1}         2      100% of CPU2
282
283
284
285       --cpu-period=0
286         Limit the CPU CFS (Completely Fair Scheduler) period.
287
288
289       Limit the container's  CPU  usage.  This  flag  causes  the  kernel  to
290       restrict the
291         container's CPU usage to the period you specify.
292
293
294       --cpu-quota=0
295         Limit the CPU CFS (Completely Fair Scheduler) quota.
296
297
298       By default, containers run with the full CPU resource. This flag causes
299       the kernel to restrict the container's CPU usage to the quota you spec‐
300       ify.
301
302
303       --cpuset-cpus=CPUSET-CPUS
304         CPUs in which to allow execution (0-3, 0,1).
305
306
307       --cpuset-mems=CPUSET-MEMS
308         Memory  nodes  (MEMs)  in  which  to allow execution (0-3, 0,1). Only
309       effective on
310         NUMA systems.
311
312
313       For example, if you have four memory nodes on your  system  (0-3),  use
314       --cpuset-mems=0,1 to ensure the processes in your Docker container only
315       use memory from the first two memory nodes.
316
317
318       --cgroup-parent=CGROUP-PARENT
319         Path to cgroups under which the container's cgroup are created.
320
321
322       If the path is not absolute, the path is  considered  relative  to  the
323       cgroups  path  of the init process.  Cgroups are created if they do not
324       already exist.
325
326
327       --target=""
328          Set the target build stage name.
329
330
331       --ulimit=[]
332         Ulimit options
333
334
335       For more information about ulimit see Setting ulimits  in  a  container
336https://docs.docker.com/engine/reference/commandline/run/#set-ulimits-
337       in-container---ulimit⟩
338
339
340

EXAMPLES

Building an image using a Dockerfile located inside the current directory

343       Docker images can be built using the build command and a Dockerfile:
344
345
346              docker build .
347
348
349
350       During the build process Docker creates intermediate images.  In  order
351       to keep them, you must explicitly set --rm=false.
352
353
354              docker build --rm=false .
355
356
357
358       A good practice is to make a sub-directory with a related name and cre‐
359       ate the Dockerfile in that directory. For example, a  directory  called
360       mongo  may contain a Dockerfile to create a Docker MongoDB image. Like‐
361       wise, another directory called httpd may be used to  store  Dockerfiles
362       for Apache web server images.
363
364
365       It  is  also a good practice to add the files required for the image to
366       the sub-directory. These files will then be specified with the COPY  or
367       ADD instructions in the Dockerfile.
368
369
370       Note:  If  you  include  a tar file (a good practice), then Docker will
371       automatically extract the contents of the tar file specified within the
372       ADD instruction into the specified target.
373
374

Building an image and naming that image

376       A  good  practice is to give a name to the image you are building. Note
377       that only a-z0-9-_. should be used for consistency.  There are no  hard
378       rules here but it is best to give the names consideration.
379
380
381       The -t/--tag flag is used to rename an image. Here are some examples:
382
383
384       Though it is not a good practice, image names can be arbitrary:
385
386
387              docker build -t myimage .
388
389
390
391       A better approach is to provide a fully qualified and meaningful repos‐
392       itory, name, and tag (where the tag in this context means the qualifier
393       after  the  ":"). In this example we build a JBoss image for the Fedora
394       repository and give it the version 1.0:
395
396
397              docker build -t fedora/jboss:1.0 .
398
399
400
401       The next example is for the "whenry" user repository  and  uses  Fedora
402       and JBoss and gives it the version 2.1 :
403
404
405              docker build -t whenry/fedora-jboss:v2.1 .
406
407
408
409       If you do not provide a version tag then Docker will assign latest:
410
411
412              docker build -t whenry/fedora-jboss .
413
414
415
416       When you list the images, the image above will have the tag latest.
417
418
419       You can apply multiple tags to an image. For example, you can apply the
420       latest tag to a newly built image and add another tag that references a
421       specific   version.    For   example,   to   tag   an   image  both  as
422       whenry/fedora-jboss:latest and whenry/fedora-jboss:v2.1, use  the  fol‐
423       lowing:
424
425
426              docker build -t whenry/fedora-jboss:latest -t whenry/fedora-jboss:v2.1 .
427
428
429
430       So  renaming an image is arbitrary but consideration should be given to
431       a useful convention that makes sense for consumers and should also take
432       into account Docker community conventions.
433
434

Building an image using a URL

436       This will clone the specified GitHub repository from the URL and use it
437       as context. The Dockerfile at the root of the  repository  is  used  as
438       Dockerfile.  This  only  works  if the GitHub repository is a dedicated
439       repository.
440
441
442              docker build github.com/scollier/purpletest
443
444
445
446       Note: You can set an arbitrary Git repository via the git:// scheme.
447
448

Building an image using a URL to a tarball'ed context

450       This will send the URL itself to the Docker  daemon.  The  daemon  will
451       fetch  the  tarball  archive, decompress it and use its contents as the
452       build context.  The Dockerfile at the root of the archive and the  rest
453       of  the  archive will get used as the context of the build. If you pass
454       an -f PATH/Dockerfile option as well, the system  will  look  for  that
455       file inside the contents of the tarball.
456
457
458              docker build -f dev/Dockerfile https://10.10.10.1/docker/context.tar.gz
459
460
461
462       Note:  supported  compression  formats  are  'xz',  'bzip2', 'gzip' and
463       'identity' (no compression).
464
465

Specify isolation technology for container (--isolation)

467       This option is useful in situations where you are running  Docker  con‐
468       tainers  on  Windows. The --isolation=<value> option sets a container's
469       isolation technology. On Linux,  the  only  supported  is  the  default
470       option which uses Linux namespaces. On Microsoft Windows, you can spec‐
471       ify these values:
472
473
474              · default: Use  the  value  specified  by  the  Docker  daemon's
475                --exec-opt . If the daemon does not specify an isolation tech‐
476                nology, Microsoft Windows uses process as its default value.
477
478              · process: Namespace isolation only.
479
480              · hyperv: Hyper-V hypervisor partition-based isolation.
481
482
483
484       Specifying the --isolation flag without a value is the same as  setting
485       --isolation="default".
486
487
488

HISTORY

490       March  2014, Originally compiled by William Henry (whenry at redhat dot
491       com) based on docker.com source material and internal work.  June 2014,
492       updated   by   Sven   Dowideit  SvenDowideit@home.org.au  ⟨mailto:Sven‐
493       Dowideit@home.org.au⟩ June  2015,  updated  by  Sally  O'Malley  somal‐
494       ley@redhat.com ⟨mailto:somalley@redhat.com⟩
495
496
497
498Manuals                              User                    DOCKER(1)(Docker)
Impressum