1DOCKER(1)(Docker) DOCKER(1)(Docker)
2
3
4
5Docker Community JUNE 2014
6
7
9 docker-run - Run a command in a new container
10
11
12
14 docker run [-a|--attach[=[]]] [--add-host[=[]]]
15 [--blkio-weight[=[BLKIO-WEIGHT]]] [--blkio-weight-device[=[]]]
16 [--cpu-shares[=0]] [--cap-add[=[]]] [--cap-drop[=[]]] [--cgroup-par‐
17 ent[=CGROUP-PATH]] [--cidfile[=CIDFILE]] [--cpu-count[=0]] [--cpu-per‐
18 cent[=0]] [--cpu-period[=0]] [--cpu-quota[=0]] [--cpu-rt-period[=0]]
19 [--cpu-rt-runtime[=0]] [--cpus[=0.0]] [--cpuset-cpus[=CPUSET-CPUS]]
20 [--cpuset-mems[=CPUSET-MEMS]] [-d|--detach] [--detach-keys[=[]]]
21 [--device[=[]]] [--device-cgroup-rule[=[]]] [--device-read-bps[=[]]]
22 [--device-read-iops[=[]]] [--device-write-bps[=[]]]
23 [--device-write-iops[=[]]] [--dns[=[]]] [--dns-option[=[]]]
24 [--dns-search[=[]]] [-e|--env[=[]]] [--entrypoint[=ENTRYPOINT]]
25 [--env-file[=[]]] [--expose[=[]]] [--group-add[=[]]] [-h|--host‐
26 name[=HOSTNAME]] [--help] [--init] [-i|--interactive]
27 [--ip[=IPv4-ADDRESS]] [--ip6[=IPv6-ADDRESS]] [--ipc[=IPC]] [--isola‐
28 tion[=default]] [--kernel-memory[=KERNEL-MEMORY]] [-l|--label[=[]]]
29 [--label-file[=[]]] [--link[=[]]] [--link-local-ip[=[]]]
30 [--log-driver[=[]]] [--log-opt[=[]]] [-m|--memory[=MEMORY]]
31 [--mac-address[=MAC-ADDRESS]] [--memory-reservation[=MEMORY-RESERVA‐
32 TION]] [--memory-swap[=LIMIT]] [--memory-swappiness[=MEMORY-SWAPPI‐
33 NESS]] [--mount[=[MOUNT]]] [--name[=NAME]] [--network-alias[=[]]]
34 [--network[="bridge"]] [--oom-kill-disable] [--oom-score-adj[=0]]
35 [-P|--publish-all] [-p|--publish[=[]]] [--pid[=[PID]]] [--userns[=[]]]
36 [--pids-limit[=PIDS_LIMIT]] [--privileged] [--read-only]
37 [--restart[=RESTART]] [--rm] [--security-opt[=[]]] [--storage-opt[=[]]]
38 [--stop-signal[=SIGNAL]] [--stop-timeout[=TIMEOUT]] [--shm-size[=[]]]
39 [--sig-proxy[=true]] [--sysctl[=[]]] [-t|--tty] [--tmpfs[=[CON‐
40 TAINER-DIR[:OPTIONS]]] [-u|--user[=USER]] [--ulimit[=[]]] [--uts[=[]]]
41 [-v|--volume[=[[HOST-DIR:]CONTAINER-DIR[:OPTIONS]]]] [--vol‐
42 ume-driver[=DRIVER]] [--volumes-from[=[]]] [-w|--workdir[=WORKDIR]]
43 IMAGE [COMMAND] [ARG...]
44
45
46
48 Run a process in a new container. docker run starts a process with its
49 own file system, its own networking, and its own isolated process tree.
50 The IMAGE which starts the process may define defaults related to the
51 process that will be run in the container, the networking to expose,
52 and more, but docker run gives final control to the operator or admin‐
53 istrator who starts the container from the image. For that reason
54 docker run has more options than any other Docker command.
55
56
57 If the IMAGE is not already loaded then docker run will pull the IMAGE,
58 and all image dependencies, from the repository in the same way running
59 docker pull IMAGE, before it starts the container from that image.
60
61
62
64 -a, --attach=[]
65 Attach to STDIN, STDOUT or STDERR.
66
67
68 In foreground mode (the default when -d is not specified), docker run
69 can start the process in the container and attach the console to the
70 process's standard input, output, and standard error. It can even pre‐
71 tend to be a TTY (this is what most commandline executables expect) and
72 pass along signals. The -a option can be set for each of stdin, stdout,
73 and stderr.
74
75
76 --add-host=[]
77 Add a custom host-to-IP mapping (host:ip)
78
79
80 Add a line to /etc/hosts. The format is hostname:ip. The --add-host
81 option can be set multiple times.
82
83
84 --blkio-weight=0
85 Block IO weight (relative weight) accepts a weight value between 10
86 and 1000.
87
88
89 --blkio-weight-device=[]
90 Block IO weight (relative device weight, format:
91 DEVICE_NAME:WEIGHT).
92
93
94 --cpu-shares=0
95 CPU shares (relative weight)
96
97
98 By default, all containers get the same proportion of CPU cycles. This
99 proportion can be modified by changing the container's CPU share
100 weighting relative to the weighting of all other running containers.
101
102
103 To modify the proportion from the default of 1024, use the --cpu-shares
104 flag to set the weighting to 2 or higher.
105
106
107 The proportion will only apply when CPU-intensive processes are run‐
108 ning. When tasks in one container are idle, other containers can use
109 the left-over CPU time. The actual amount of CPU time will vary depend‐
110 ing on the number of containers running on the system.
111
112
113 For example, consider three containers, one has a cpu-share of 1024 and
114 two others have a cpu-share setting of 512. When processes in all three
115 containers attempt to use 100% of CPU, the first container would
116 receive 50% of the total CPU time. If you add a fourth container with a
117 cpu-share of 1024, the first container only gets 33% of the CPU. The
118 remaining containers receive 16.5%, 16.5% and 33% of the CPU.
119
120
121 On a multi-core system, the shares of CPU time are distributed over all
122 CPU cores. Even if a container is limited to less than 100% of CPU
123 time, it can use 100% of each individual CPU core.
124
125
126 For example, consider a system with more than three cores. If you start
127 one container {C0} with -c=512 running one process, and another con‐
128 tainer {C1} with -c=1024 running two processes, this can result in the
129 following division of CPU shares:
130
131
132 PID container CPU CPU share
133 100 {C0} 0 100% of CPU0
134 101 {C1} 1 100% of CPU1
135 102 {C1} 2 100% of CPU2
136
137
138
139 --cap-add=[]
140 Add Linux capabilities
141
142
143 --cap-drop=[]
144 Drop Linux capabilities
145
146
147 --cgroup-parent=""
148 Path to cgroups under which the cgroup for the container will be
149 created. If the path is not absolute, the path is considered to be rel‐
150 ative to the cgroups path of the init process. Cgroups will be created
151 if they do not already exist.
152
153
154 --cidfile=""
155 Write the container ID to the file
156
157
158 --cpu-count=0
159 Limit the number of CPUs available for execution by the container.
160
161
162 On Windows Server containers, this is approximated as a percentage of total CPU usage.
163
164 On Windows Server containers, the processor resource controls are mutually exclusive, the order of precedence is CPUCount first, then CPUShares, and CPUPercent last.
165
166
167
168 --cpu-percent=0
169 Limit the percentage of CPU available for execution by a container
170 running on a Windows daemon.
171
172
173 On Windows Server containers, the processor resource controls are mutually exclusive, the order of precedence is CPUCount first, then CPUShares, and CPUPercent last.
174
175
176
177 --cpu-period=0
178 Limit the CPU CFS (Completely Fair Scheduler) period
179
180
181 Limit the container's CPU usage. This flag tell the kernel to restrict
182 the container's CPU usage to the period you specify.
183
184
185 --cpuset-cpus=""
186 CPUs in which to allow execution (0-3, 0,1)
187
188
189 --cpuset-mems=""
190 Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only
191 effective on NUMA systems.
192
193
194 If you have four memory nodes on your system (0-3), use
195 --cpuset-mems=0,1 then processes in your Docker container will only use
196 memory from the first two memory nodes.
197
198
199 --cpu-quota=0
200 Limit the CPU CFS (Completely Fair Scheduler) quota
201
202
203 Limit the container's CPU usage. By default, containers run with the
204 full CPU resource. This flag tell the kernel to restrict the con‐
205 tainer's CPU usage to the quota you specify.
206
207
208 --cpu-rt-period=0
209 Limit the CPU real-time period in microseconds
210
211
212 Limit the container's Real Time CPU usage. This flag tell the kernel to
213 restrict the container's Real Time CPU usage to the period you specify.
214
215
216 --cpu-rt-runtime=0
217 Limit the CPU real-time runtime in microseconds
218
219
220 Limit the containers Real Time CPU usage. This flag tells the kernel to
221 limit the amount of time in a given CPU period Real Time tasks may con‐
222 sume. Ex:
223 Period of 1,000,000us and Runtime of 950,000us means that this con‐
224 tainer could consume 95% of available CPU and leave the remaining 5% to
225 normal priority tasks.
226
227
228 The sum of all runtimes across containers cannot exceed the amount
229 allotted to the parent cgroup.
230
231
232 --cpus=0.0
233 Number of CPUs. The default is 0.0 which means no limit.
234
235
236 -d, --detach=true|false
237 Detached mode: run the container in the background and print the new
238 container ID. The default is false.
239
240
241 At any time you can run docker ps in the other shell to view a list of
242 the running containers. You can reattach to a detached container with
243 docker attach.
244
245
246 When attached in the tty mode, you can detach from the container (and
247 leave it running) using a configurable key sequence. The default
248 sequence is CTRL-p CTRL-q. You configure the key sequence using the
249 --detach-keys option or a configuration file. See config-json(5) for
250 documentation on using a configuration file.
251
252
253 --detach-keys=key
254 Override the key sequence for detaching a container; key is a single
255 character from the [a-Z] range, or ctrl-value, where value is one of:
256 a-z, @, ^, [, ,, or _.
257
258
259 --device=onhost:incontainer[:mode]
260 Add a host device onhost to the container under the incontainer
261 name. Optional mode parameter can be used to specify device permis‐
262 sions, it is a combination of r (for read), w (for write), and m (for
263 mknod(2)).
264
265
266 For example, --device=/dev/sdc:/dev/xvdc:rwm will give a container all
267 permissions for the host device /dev/sdc, seen as /dev/xvdc inside the
268 container.
269
270
271 --device-cgroup-rule="type major:minor mode"
272 Add a rule to the cgroup allowed devices list. The rule is expected
273 to be in the format specified in the Linux kernel documentation (Docu‐
274 mentation/cgroup-v1/devices.txt):
275 - type: a (all), c (char), or b (block);
276 - major and minor: either a number, or * for all;
277 - mode: a composition of r (read), w (write), and m (mknod(2)).
278
279
280 Example: --device-cgroup-rule "c 1:3 mr": allow for a character device
281 idendified by 1:3 to be created and read.
282
283
284 --device-read-bps=[]
285 Limit read rate from a device (e.g. --device-read-bps=/dev/sda:1mb)
286
287
288 --device-read-iops=[]
289 Limit read rate from a device (e.g.
290 --device-read-iops=/dev/sda:1000)
291
292
293 --device-write-bps=[]
294 Limit write rate to a device (e.g. --device-write-bps=/dev/sda:1mb)
295
296
297 --device-write-iops=[]
298 Limit write rate to a device (e.g.
299 --device-write-iops=/dev/sda:1000)
300
301
302 --dns-search=[]
303 Set custom DNS search domains (Use --dns-search=. if you don't wish
304 to set the search domain)
305
306
307 --dns-option=[]
308 Set custom DNS options
309
310
311 --dns=[]
312 Set custom DNS servers
313
314
315 This option can be used to override the DNS configuration passed to the
316 container. Typically this is necessary when the host DNS configuration
317 is invalid for the container (e.g., 127.0.0.1). When this is the case
318 the --dns flags is necessary for every run.
319
320
321 -e, --env=[]
322 Set environment variables
323
324
325 This option allows you to specify arbitrary environment variables that
326 are available for the process that will be launched inside of the con‐
327 tainer.
328
329
330 --entrypoint=""
331 Overwrite the default ENTRYPOINT of the image
332
333
334 This option allows you to overwrite the default entrypoint of the image
335 that is set in the Dockerfile. The ENTRYPOINT of an image is similar to
336 a COMMAND because it specifies what executable to run when the con‐
337 tainer starts, but it is (purposely) more difficult to override. The
338 ENTRYPOINT gives a container its default nature or behavior, so that
339 when you set an ENTRYPOINT you can run the container as if it were that
340 binary, complete with default options, and you can pass in more options
341 via the COMMAND. But, sometimes an operator may want to run something
342 else inside the container, so you can override the default ENTRYPOINT
343 at runtime by using a --entrypoint and a string to specify the new
344 ENTRYPOINT.
345
346
347 --env-file=[]
348 Read in a line delimited file of environment variables
349
350
351 --expose=[]
352 Expose a port, or a range of ports (e.g. --expose=3300-3310) informs
353 Docker that the container listens on the specified network ports at
354 runtime. Docker uses this information to interconnect containers using
355 links and to set up port redirection on the host system.
356
357
358 --group-add=[]
359 Add additional groups to run as
360
361
362 -h, --hostname=""
363 Container host name
364
365
366 Sets the container host name that is available inside the container.
367
368
369 --help
370 Print usage statement
371
372
373 --init
374 Run an init inside the container that forwards signals and reaps
375 processes
376
377
378 -i, --interactive=true|false
379 Keep STDIN open even if not attached. The default is false.
380
381
382 When set to true, keep stdin open even if not attached.
383
384
385 --ip=""
386 Sets the container's interface IPv4 address (e.g., 172.23.0.9)
387
388
389 It can only be used in conjunction with --network for user-defined net‐
390 works
391
392
393 --ip6=""
394 Sets the container's interface IPv6 address (e.g., 2001:db8::1b99)
395
396
397 It can only be used in conjunction with --network for user-defined net‐
398 works
399
400
401 --ipc=""
402 Sets the IPC mode for the container. The following values are
403 accepted:
404
405
406 ┌─────────────────────┬────────────────────────────┐
407 │Value │ Description │
408 ├─────────────────────┼────────────────────────────┤
409 │(empty) │ Use daemon's default. │
410 ├─────────────────────┼────────────────────────────┤
411 │none │ Own private IPC namespace, │
412 │ │ with /dev/shm not mounted. │
413 ├─────────────────────┼────────────────────────────┤
414 │private │ Own private IPC namespace. │
415 ├─────────────────────┼────────────────────────────┤
416 │shareable │ Own private IPC namespace, │
417 │ │ with a possibility to │
418 │ │ share it with other con‐ │
419 │ │ tainers. │
420 ├─────────────────────┼────────────────────────────┤
421 │container:name-or-ID │ Join another ("shareable") │
422 │ │ container's IPC namespace. │
423 ├─────────────────────┼────────────────────────────┤
424 │host │ Use the host system's IPC │
425 │ │ namespace. │
426 └─────────────────────┴────────────────────────────┘
427
428 If not specified, daemon default is used, which can either be private
429 or shareable, depending on the daemon version and configuration.
430
431
432 --isolation="default"
433 Isolation specifies the type of isolation technology used by con‐
434 tainers. Note that the default on Windows server is process, and the
435 default on Windows client is hyperv. Linux only supports default.
436
437
438 -l, --label key=value
439 Set metadata on the container (for example, --label com.exam‐
440 ple.key=value).
441
442
443 --kernel-memory=number[S]
444 Kernel memory limit; S is an optional suffix which can be one of b,
445 k, m, or g.
446
447
448 Constrains the kernel memory available to a container. If a limit of 0
449 is specified (not using --kernel-memory), the container's kernel memory
450 is not limited. If you specify a limit, it may be rounded up to a mul‐
451 tiple of the operating system's page size and the value can be very
452 large, millions of trillions.
453
454
455 --label-file=[]
456 Read in a line delimited file of labels
457
458
459 --link=name-or-id[:alias]
460 Add link to another container.
461
462
463 If the operator uses --link when starting the new client container,
464 then the client container can access the exposed port via a private
465 networking interface. Docker will set some environment variables in the
466 client container to help indicate which interface and port to use.
467
468
469 --link-local-ip=[]
470 Add one or more link-local IPv4/IPv6 addresses to the container's
471 interface
472
473
474 --log-driver="json-file|syslog|journald|gelf|flu‐
475 entd|awslogs|splunk|etwlogs|gcplogs|none"
476 Logging driver for the container. Default is defined by daemon
477 --log-driver flag.
478 Warning: the docker logs command works only for the json-file and
479 journald logging drivers.
480
481
482 --log-opt=[]
483 Logging driver specific options.
484
485
486 -m, --memory=number[*S]
487 Memory limit; S is an optional suffix which can be one of b, k, m,
488 or g.
489
490
491 Allows you to constrain the memory available to a container. If the
492 host supports swap memory, then the -m memory setting can be larger
493 than physical RAM. If a limit of 0 is specified (not using -m), the
494 container's memory is not limited. The actual limit may be rounded up
495 to a multiple of the operating system's page size (the value would be
496 very large, that's millions of trillions).
497
498
499 --memory-reservation=number[*S]
500 Memory soft limit; S is an optional suffix which can be one of b, k,
501 m, or g.
502
503
504 After setting memory reservation, when the system detects memory con‐
505 tention or low memory, containers are forced to restrict their consump‐
506 tion to their reservation. So you should always set the value below
507 --memory, otherwise the hard limit will take precedence. By default,
508 memory reservation will be the same as memory limit.
509
510
511 --memory-swap=number[S]
512 Combined memory plus swap limit; S is an optional suffix which can
513 be one of b, k, m, or g.
514
515
516 This option can only be used together with --memory. The argument
517 should always be larger than that of --memory. Default is double the
518 value of --memory. Set to -1 to enable unlimited swap.
519
520
521 --mac-address=""
522 Container MAC address (e.g., 92:d0:c6:0a:29:33)
523
524
525 Remember that the MAC address in an Ethernet network must be unique.
526 The IPv6 link-local address will be based on the device's MAC address
527 according to RFC4862.
528
529
530 --mount type=TYPE,TYPE-SPECIFIC-OPTION[,...]
531 Attach a filesystem mount to the container
532
533
534 Current supported mount TYPES are bind, volume, and tmpfs.
535
536
537 e.g.
538
539
540 type=bind,source=/path/on/host,destination=/path/in/container
541
542
543 type=volume,source=my-volume,destination=/path/in/container,vol‐
544 ume-label="color=red",volume-label="shape=round"
545
546
547 type=tmpfs,tmpfs-size=512M,destination=/path/in/container
548
549
550 Common Options:
551
552
553 · src, source: mount source spec for bind and volume. Mandatory
554 for bind.
555
556 · dst, destination, target: mount destination spec.
557
558 · ro, read-only: true or false (default).
559
560
561
562 Options specific to bind:
563
564
565 · bind-propagation: shared, slave, private, rshared, rslave, or
566 rprivate(default). See also mount(2).
567
568 · consistency: consistent(default), cached, or delegated. Cur‐
569 rently, only effective for Docker for Mac.
570
571
572
573 Options specific to volume:
574
575
576 · volume-driver: Name of the volume-driver plugin.
577
578 · volume-label: Custom metadata.
579
580 · volume-nocopy: true(default) or false. If set to false, the
581 Engine copies existing files and directories under the
582 mount-path into the volume, allowing the host to access them.
583
584 · volume-opt: specific to a given volume driver.
585
586
587
588 Options specific to tmpfs:
589
590
591 · tmpfs-size: Size of the tmpfs mount in bytes. Unlimited by
592 default in Linux.
593
594 · tmpfs-mode: File mode of the tmpfs in octal. (e.g. 700 or
595 0700.) Defaults to 1777 in Linux.
596
597
598
599 --name=""
600 Assign a name to the container
601
602
603 The operator can identify a container in three ways:
604
605
606 ┌──────────────────────┬────────────────────────────────────────────────────────────────────┐
607 │Identifier type │ Example value │
608 ├──────────────────────┼────────────────────────────────────────────────────────────────────┤
609 │UUID long identifier │ "f78375b1c487e03c9438c729345e54db9d20cfa2ac1fc3494b6eb60872e74778" │
610 ├──────────────────────┼────────────────────────────────────────────────────────────────────┤
611 │UUID short identifier │ "f78375b1c487" │
612 ├──────────────────────┼────────────────────────────────────────────────────────────────────┤
613 │Name │ "evil_ptolemy" │
614 └──────────────────────┴────────────────────────────────────────────────────────────────────┘
615
616 The UUID identifiers come from the Docker daemon, and if a name is not
617 assigned to the container with --name then the daemon will also gener‐
618 ate a random string name. The name is useful when defining links (see
619 --link) (or any other place you need to identify a container). This
620 works for both background and foreground Docker containers.
621
622
623 --network=type
624 Set the Network mode for the container. Supported values are:
625
626
627 ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬────────────────────────────┐
628 │Value │ Description │
629 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
630 │none │ No networking in the con‐ │
631 │ │ tainer. │
632 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
633 │bridge │ Connect the container to │
634 │ │ the default Docker bridge │
635 │ │ via veth interfaces. │
636 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
637 │host │ Use the host's network │
638 │ │ stack inside the con‐ │
639 │ │ tainer. │
640 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
641 │container:name │ │
642 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
643 │idnetwork-name │ │
644 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
645 │network-id.TE │ │
646 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
647 │ │ │
648 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
649 │ │ │
650 │Default is bridge. │ │
651 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
652 │ │ │
653 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
654 │ │ │
655 │--network-alias=[] │ │
656 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
657 │ Add network-scoped alias for the container │ │
658 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
659 │ │ │
660 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
661 │ │ │
662 │--oom-kill-disable=true|false │ │
663 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
664 │ Whether to disable OOM Killer for the container or not. │ │
665 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
666 │ │ │
667 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
668 │ │ │
669 │--oom-score-adj="" │ │
670 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
671 │ Tune the host's OOM preferences for containers (accepts -1000 to 1000) │ │
672 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
673 │ │ │
674 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
675 │ │ │
676 │-P, --publish-all=true|false │ │
677 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
678 │ Publish all exposed ports to random ports on the host interfaces. The default is false. │ │
679 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
680 │ │ │
681 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
682 │ │ │
683 │When set to true publish all exposed ports to the host interfaces. The │ │
684 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
685 │default is false. If the operator uses -P (or -p) then Docker will make the │ │
686 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
687 │exposed port accessible on the host and the ports will be available to any │ │
688 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
689 │client that can reach the host. When using -P, Docker will bind any exposed │ │
690 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
691 │port to a random port on the host within an ephemeral port range defined by │ │
692 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
693 │/proc/sys/net/ipv4/ip_local_port_range. To find the mapping between the host │ │
694 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
695 │ports and the exposed ports, use docker port(1). │ │
696 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
697 │ │ │
698 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
699 │ │ │
700 │-p, --publish ip:[hostPort]:containerPort | [hostPort:]containerPort │ │
701 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
702 │ Publish a container's port, or range of ports, to the host. │ │
703 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
704 │ │ │
705 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
706 │ │ │
707 │Both hostPort and containerPort can be specified as a range. │ │
708 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
709 │When specifying ranges for both, the number of ports in ranges should be equal. │ │
710 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
711 │ │ │
712 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
713 │ │ │
714 │Examples: -p 1234-1236:1222-1224, -p 127.0.0.1:$HOSTPORT:$CONTAINERPORT. │ │
715 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
716 │ │ │
717 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
718 │ │ │
719 │Use docker port(1) to see the actual mapping, e.g. docker port CONTAINER $CONTAINERPORT. │ │
720 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
721 │ │ │
722 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
723 │ │ │
724 │--pid="" │ │
725 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
726 │ Set the PID mode for the container │ │
727 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
728 │ Default is to create a private PID namespace for the container │ │
729 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
730 │ 'container:': join another container's PID namespace │ │
731 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
732 │ 'host': use the host's PID namespace for the container. Note: the host mode gives the container full access to local PID and is therefore considered insecure. │ │
733 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
734 │ │ │
735 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
736 │ │ │
737 │--userns="" │ │
738 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
739 │ Set the usernamespace mode for the container when userns-remap option is enabled. │ │
740 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
741 │ host: use the host usernamespace and enable all privileged options (e.g., pid=host or --privileged). │ │
742 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
743 │ │ │
744 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
745 │ │ │
746 │--pids-limit="" │ │
747 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
748 │ Tune the container's pids (process IDs) limit. Set to -1 to have unlimited pids for the container. │ │
749 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
750 │ │ │
751 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
752 │ │ │
753 │--uts=type │ │
754 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
755 │ Set the UTS mode for the container. The only possible type is host, meaning to │ │
756 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
757 │use the host's UTS namespace inside the container. │ │
758 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
759 │ Note: the host mode gives the container access to changing the host's hostname and is therefore considered insecure. │ │
760 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
761 │ │ │
762 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
763 │ │ │
764 │--privileged [true|false] │ │
765 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
766 │ Give extended privileges to this container. A "privileged" container is given access to all devices. │ │
767 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
768 │ │ │
769 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
770 │ │ │
771 │When the operator executes docker run --privileged, Docker will enable access │ │
772 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
773 │to all devices on the host as well as set some configuration in AppArmor to │ │
774 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
775 │allow the container nearly all the same access to the host as processes running │ │
776 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
777 │outside of a container on the host. │ │
778 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
779 │ │ │
780 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
781 │ │ │
782 │--read-only=true|false │ │
783 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
784 │ Mount the container's root filesystem as read only. │ │
785 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
786 │ │ │
787 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
788 │ │ │
789 │By default a container will have its root filesystem writable allowing processes │ │
790 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
791 │to write files anywhere. By specifying the --read-only flag the container will have │ │
792 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
793 │its root filesystem mounted as read only prohibiting any writes. │ │
794 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
795 │ │ │
796 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
797 │ │ │
798 │--restart policy │ │
799 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
800 │ Restart policy to apply when a container exits. Supported values are: │ │
801 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
802 │ │ │
803 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
804 │ │ │
805 │allbox; │ │
806 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
807 │l l │ │
808 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
809 │l l . │ │
810 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
811 │Policy │ Result │
812 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
813 │no │ Do not automatically │
814 │ │ restart the container when │
815 │ │ it exits. │
816 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
817 │on-failure[:max-retries] │ Restart only if the con‐ │
818 │ │ tainer exits with a │
819 │ │ non-zero exit status. │
820 │ │ Optionally, limit the num‐ │
821 │ │ ber of restart retries the │
822 │ │ Docker daemon attempts. │
823 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
824 │always │ Always restart the con‐ │
825 │ │ tainer regardless of the │
826 │ │ exit status. When you │
827 │ │ specify always, the Docker │
828 │ │ daemon will try to restart │
829 │ │ the container indefi‐ │
830 │ │ nitely. The container will │
831 │ │ also always start on dae‐ │
832 │ │ mon startup, regardless of │
833 │ │ the current state of the │
834 │ │ container. │
835 ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────┤
836 │unless-stopped │ Always restart the con‐ │
837 │ │ tainer regardless of the │
838 │ │ exit status, but do not │
839 │ │ start it on daemon startup │
840 │ │ if the container has been │
841 │ │ put to a stopped state │
842 │ │ before. │
843 └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴────────────────────────────┘
844
845 Default is no.
846
847
848 --rm true|false
849 Automatically remove the container when it exits. The default is
850 false.
851 --rm flag can work together with -d, and auto-removal will be done
852 on daemon side. Note that it's incompatible with any restart policy
853 other than none.
854
855
856 --security-opt value[,...]
857 Security Options for the container. The following options can be
858 given:
859
860
861 "label=user:USER" : Set the label user for the container
862 "label=role:ROLE" : Set the label role for the container
863 "label=type:TYPE" : Set the label type for the container
864 "label=level:LEVEL" : Set the label level for the container
865 "label=disable" : Turn off label confinement for the container
866 "no-new-privileges" : Disable container processes from gaining additional privileges
867
868 "seccomp=unconfined" : Turn off seccomp confinement for the container
869 "seccomp=profile.json : White listed syscalls seccomp Json file to be used as a seccomp filter
870
871 "apparmor=unconfined" : Turn off apparmor confinement for the container
872 "apparmor=your-profile" : Set the apparmor confinement profile for the container
873
874
875
876 --storage-opt
877 Storage driver options per container
878
879
880 $ docker run -it --storage-opt size=120G fedora /bin/bash
881
882
883 This (size) will allow to set the container rootfs size to 120G at cre‐
884 ation time.
885 This option is only available for the devicemapper, btrfs, overlay2
886 and zfs graph drivers.
887 For the devicemapper, btrfs and zfs storage drivers, user cannot
888 pass a size less than the Default BaseFS Size.
889 For the overlay2 storage driver, the size option is only available
890 if the backing fs is xfs and mounted with the pquota mount option.
891 Under these conditions, user can pass any size less than the backing
892 fs size.
893
894
895 --stop-signal=SIGTERM
896 Signal to stop a container. Default is SIGTERM.
897
898
899 --stop-timeout=10
900 Timeout (in seconds) to stop a container. Default is 10.
901
902
903 --shm-size=""
904 Size of /dev/shm. The format is <number><unit>.
905 number must be greater than 0. Unit is optional and can be b
906 (bytes), k (kilobytes), m(megabytes), or g (gigabytes).
907 If you omit the unit, the system uses bytes. If you omit the size
908 entirely, the system uses 64m.
909
910
911 --sysctl=SYSCTL
912 Configure namespaced kernel parameters at runtime
913
914
915 IPC Namespace - current sysctls allowed:
916
917
918 kernel.msgmax, kernel.msgmnb, kernel.msgmni, kernel.sem, kernel.shmall,
919 kernel.shmmax, kernel.shmmni, kernel.shm_rmid_forced
920 Sysctls beginning with fs.mqueue.*
921
922
923 If you use the --ipc=host option these sysctls will not be allowed.
924
925
926 Network Namespace - current sysctls allowed:
927 Sysctls beginning with net.*
928
929
930 If you use the --network=host option these sysctls will not be allowed.
931
932
933 --sig-proxy=true|false
934 Proxy received signals to the process (non-TTY mode only). SIGCHLD,
935 SIGSTOP, and SIGKILL are not proxied. The default is true.
936
937
938 --memory-swappiness=""
939 Tune a container's memory swappiness behavior. Accepts an integer
940 between 0 and 100.
941
942
943 -t, --tty=true|false
944 Allocate a pseudo-TTY. The default is false.
945
946
947 When set to true Docker can allocate a pseudo-tty and attach to the
948 standard input of any container. This can be used, for example, to run
949 a throwaway interactive shell. The default is false.
950
951
952 The -t option is incompatible with a redirection of the docker client
953 standard input.
954
955
956 --tmpfs=[] Create a tmpfs mount
957
958
959 Mount a temporary filesystem (tmpfs) mount into a container, for exam‐
960 ple:
961
962
963 $ docker run -d --tmpfs /tmp:rw,size=787448k,mode=1777 my_image
964
965
966 This command mounts a tmpfs at /tmp within the container. The sup‐
967 ported mount options are the same as the Linux default mount flags. If
968 you do not specify any options, the systems uses the following options:
969 rw,noexec,nosuid,nodev,size=65536k.
970
971
972 See also --mount, which is the successor of --tmpfs and --volume.
973 Even though there is no plan to deprecate --tmpfs, usage of --mount
974 is recommended.
975
976
977 -u, --user=""
978 Sets the username or UID used and optionally the groupname or GID
979 for the specified command.
980
981
982 The followings examples are all valid:
983 --user [user | user:group | uid | uid:gid | user:gid | uid:group ]
984
985
986 Without this argument the command will be run as root in the container.
987
988
989 --ulimit=[]
990 Ulimit options
991
992
993 -v|--volume[=[[HOST-DIR:]CONTAINER-DIR[:OPTIONS]]]
994 Create a bind mount. If you specify, -v /HOST-DIR:/CONTAINER-DIR,
995 Docker
996 bind mounts /HOST-DIR in the host to /CONTAINER-DIR in the Docker
997 container. If 'HOST-DIR' is omitted, Docker automatically creates
998 the new
999 volume on the host. The OPTIONS are a comma delimited list and can
1000 be:
1001
1002
1003 · [rw|ro]
1004
1005 · [z|Z]
1006
1007 · [[r]shared|[r]slave|[r]private]
1008
1009 · [delegated|cached|consistent]
1010
1011 · [nocopy]
1012
1013
1014
1015 The CONTAINER-DIR must be an absolute path such as /src/docs. The
1016 HOST-DIR can be an absolute path or a name value. A name value must
1017 start with an alphanumeric character, followed by a-z0-9, _ (under‐
1018 score), . (period) or - (hyphen). An absolute path starts with a /
1019 (forward slash).
1020
1021
1022 If you supply a HOST-DIR that is an absolute path, Docker bind-mounts
1023 to the path you specify. If you supply a name, Docker creates a named
1024 volume by that name. For example, you can specify either /foo or foo
1025 for a HOST-DIR value. If you supply the /foo value, Docker creates a
1026 bind mount. If you supply the foo specification, Docker creates a named
1027 volume.
1028
1029
1030 You can specify multiple -v options to mount one or more mounts to a
1031 container. To use these same mounts in other containers, specify the
1032 --volumes-from option also.
1033
1034
1035 You can supply additional options for each bind mount following an
1036 additional colon. A :ro or :rw suffix mounts a volume in read-only or
1037 read-write mode, respectively. By default, volumes are mounted in
1038 read-write mode. You can also specify the consistency requirement for
1039 the mount, either :consistent (the default), :cached, or :delegated.
1040 Multiple options are separated by commas, e.g. :ro,cached.
1041
1042
1043 Labeling systems like SELinux require that proper labels are placed on
1044 volume content mounted into a container. Without a label, the security
1045 system might prevent the processes running inside the container from
1046 using the content. By default, Docker does not change the labels set by
1047 the OS.
1048
1049
1050 To change a label in the container context, you can add either of two
1051 suffixes :z or :Z to the volume mount. These suffixes tell Docker to
1052 relabel file objects on the shared volumes. The z option tells Docker
1053 that two containers share the volume content. As a result, Docker
1054 labels the content with a shared content label. Shared volume labels
1055 allow all containers to read/write content. The Z option tells Docker
1056 to label the content with a private unshared label. Only the current
1057 container can use a private volume.
1058
1059
1060 By default bind mounted volumes are private. That means any mounts done
1061 inside container will not be visible on host and vice-a-versa. One can
1062 change this behavior by specifying a volume mount propagation property.
1063 Making a volume shared mounts done under that volume inside container
1064 will be visible on host and vice-a-versa. Making a volume slave enables
1065 only one way mount propagation and that is mounts done on host under
1066 that volume will be visible inside container but not the other way
1067 around.
1068
1069
1070 To control mount propagation property of volume one can use :[r]shared,
1071 :[r]slave or :[r]private propagation flag. Propagation property can be
1072 specified only for bind mounted volumes and not for internal volumes or
1073 named volumes. For mount propagation to work source mount point (mount
1074 point where source dir is mounted on) has to have right propagation
1075 properties. For shared volumes, source mount point has to be shared.
1076 And for slave volumes, source mount has to be either shared or slave.
1077
1078
1079 Use df <source-dir> to figure out the source mount and then use findmnt
1080 -o TARGET,PROPAGATION <source-mount-dir> to figure out propagation
1081 properties of source mount. If findmnt utility is not available, then
1082 one can look at mount entry for source mount point in
1083 /proc/self/mountinfo. Look at optional fields and see if any propaga‐
1084 tion properties are specified. shared:X means mount is shared, mas‐
1085 ter:X means mount is slave and if nothing is there that means mount is
1086 private.
1087
1088
1089 To change propagation properties of a mount point use mount command.
1090 For example, if one wants to bind mount source directory /foo one can
1091 do mount --bind /foo /foo and mount --make-private --make-shared /foo.
1092 This will convert /foo into a shared mount point. Alternatively one can
1093 directly change propagation properties of source mount. Say / is source
1094 mount for /foo, then use mount --make-shared / to convert / into a
1095 shared mount.
1096
1097
1098 Note: When using systemd to manage the Docker daemon's start and
1099 stop, in the systemd unit file there is an option to control
1100 mount propagation for the Docker daemon itself, called Mount‐
1101 Flags. The value of this setting may cause Docker to not see
1102 mount propagation changes made on the mount point. For example,
1103 if this value is slave, you may not be able to use the shared or
1104 rshared propagation on a volume.
1105
1106
1107
1108 To disable automatic copying of data from the container path to the
1109 volume, use the nocopy flag. The nocopy flag can be set on bind mounts
1110 and named volumes.
1111
1112
1113 See also --mount, which is the successor of --tmpfs and --volume. Even
1114 though there is no plan to deprecate --volume, usage of --mount is rec‐
1115 ommended.
1116
1117
1118 --volume-driver=""
1119 Container's volume driver. This driver creates volumes specified
1120 either from
1121 a Dockerfile's VOLUME instruction or from the docker run -v flag.
1122 See docker-volume-create(1) for full details.
1123
1124
1125 --volumes-from=[]
1126 Mount volumes from the specified container(s)
1127
1128
1129 Mounts already mounted volumes from a source container onto another
1130 container. You must supply the source's container-id. To share
1131 a volume, use the --volumes-from option when running
1132 the target container. You can share volumes even if the source con‐
1133 tainer
1134 is not running.
1135
1136
1137 By default, Docker mounts the volumes in the same mode (read-write or
1138 read-only) as it is mounted in the source container. Optionally, you
1139 can change this by suffixing the container-id with either the :ro or
1140 :rw keyword.
1141
1142
1143 If the location of the volume from the source container overlaps with
1144 data residing on a target container, then the volume hides
1145 that data on the target.
1146
1147
1148 -w, --workdir=""
1149 Working directory inside the container
1150
1151
1152 The default working directory for running binaries within a container
1153 is the root directory (/). The developer can set a different default
1154 with the Dockerfile WORKDIR instruction. The operator can override the
1155 working directory by using the -w option.
1156
1157
1158
1160 The exit code from docker run gives information about why the container
1161 failed to run or why it exited. When docker run exits with a non-zero
1162 code, the exit codes follow the chroot standard, see below:
1163
1164
1165 125 if the error is with Docker daemon itself
1166
1167
1168 $ docker run --foo busybox; echo $?
1169 # flag provided but not defined: --foo
1170 See 'docker run --help'.
1171 125
1172
1173
1174
1175 126 if the contained command cannot be invoked
1176
1177
1178 $ docker run busybox /etc; echo $?
1179 # exec: "/etc": permission denied
1180 docker: Error response from daemon: Contained command could not be invoked
1181 126
1182
1183
1184
1185 127 if the contained command cannot be found
1186
1187
1188 $ docker run busybox foo; echo $?
1189 # exec: "foo": executable file not found in $PATH
1190 docker: Error response from daemon: Contained command not found or does not exist
1191 127
1192
1193
1194
1195 Exit code of contained command otherwise
1196
1197
1198 $ docker run busybox /bin/sh -c 'exit 3'
1199 # 3
1200
1201
1202
1203
1206 During container image development, containers often need to write to
1207 the image content. Installing packages into /usr, for example. In
1208 production, applications seldom need to write to the image. Container
1209 applications write to volumes if they need to write to file systems at
1210 all. Applications can be made more secure by running them in read-only
1211 mode using the --read-only switch. This protects the containers image
1212 from modification. Read only containers may still need to write tempo‐
1213 rary data. The best way to handle this is to mount tmpfs directories
1214 on /run and /tmp.
1215
1216
1217 # docker run --read-only --tmpfs /run --tmpfs /tmp -i -t fedora /bin/bash
1218
1219
1220
1222 If you want messages that are logged in your container to show up in
1223 the host's syslog/journal then you should bind mount the /dev/log
1224 directory as follows.
1225
1226
1227 # docker run -v /dev/log:/dev/log -i -t fedora /bin/bash
1228
1229
1230
1231 From inside the container you can test this by sending a message to the
1232 log.
1233
1234
1235 (bash)# logger "Hello from my container"
1236
1237
1238
1239 Then exit and check the journal.
1240
1241
1242 # exit
1243
1244 # journalctl -b | grep Hello
1245
1246
1247
1248 This should list the message sent to logger.
1249
1250
1252 If you do not specify -a then Docker will attach everything (stdin,std‐
1253 out,stderr) you'd like to connect instead, as in:
1254
1255
1256 # docker run -a stdin -a stdout -i -t fedora /bin/bash
1257
1258
1259
1261 Using shm_server.c available here:
1262 https://www.cs.cf.ac.uk/Dave/C/node27.html
1263
1264
1265 Testing --ipc=host mode:
1266
1267
1268 Host shows a shared memory segment with 7 pids attached, happens to be
1269 from httpd:
1270
1271
1272 $ sudo ipcs -m
1273
1274 ------ Shared Memory Segments --------
1275 key shmid owner perms bytes nattch status
1276 0x01128e25 0 root 600 1000 7
1277
1278
1279
1280 Now run a regular container, and it correctly does NOT see the shared
1281 memory segment from the host:
1282
1283
1284 $ docker run -it shm ipcs -m
1285
1286 ------ Shared Memory Segments --------
1287 key shmid owner perms bytes nattch status
1288
1289
1290
1291 Run a container with the new --ipc=host option, and it now sees the
1292 shared memory segment from the host httpd:
1293
1294
1295 $ docker run -it --ipc=host shm ipcs -m
1296
1297 ------ Shared Memory Segments --------
1298 key shmid owner perms bytes nattch status
1299 0x01128e25 0 root 600 1000 7
1300
1301
1302
1303 Testing --ipc=container:CONTAINERID mode:
1304
1305
1306 Start a container with a program to create a shared memory segment:
1307
1308
1309 $ docker run -it shm bash
1310 $ sudo shm/shm_server
1311 $ sudo ipcs -m
1312
1313 ------ Shared Memory Segments --------
1314 key shmid owner perms bytes nattch status
1315 0x0000162e 0 root 666 27 1
1316
1317
1318
1319 Create a 2nd container correctly shows no shared memory segment from
1320 1st container:
1321
1322
1323 $ docker run shm ipcs -m
1324
1325 ------ Shared Memory Segments --------
1326 key shmid owner perms bytes nattch status
1327
1328
1329
1330 Create a 3rd container using the new --ipc=container:CONTAINERID
1331 option, now it shows the shared memory segment from the first:
1332
1333
1334 $ docker run -it --ipc=container:ed735b2264ac shm ipcs -m
1335 $ sudo ipcs -m
1336
1337 ------ Shared Memory Segments --------
1338 key shmid owner perms bytes nattch status
1339 0x0000162e 0 root 666 27 1
1340
1341
1342
1344 Note: This section describes linking between containers on the
1345 default (bridge) network, also known as "legacy links". Using
1346 --link on user-defined networks uses the DNS-based discovery,
1347 which does not add entries to /etc/hosts, and does not set envi‐
1348 ronment variables for discovery.
1349
1350
1351
1352 The link feature allows multiple containers to communicate with each
1353 other. For example, a container whose Dockerfile has exposed port 80
1354 can be run and named as follows:
1355
1356
1357 # docker run --name=link-test -d -i -t fedora/httpd
1358
1359
1360
1361 A second container, in this case called linker, can communicate with
1362 the httpd container, named link-test, by running with the --link=:
1363
1364
1365 # docker run -t -i --link=link-test:lt --name=linker fedora /bin/bash
1366
1367
1368
1369 Now the container linker is linked to container link-test with the
1370 alias lt. Running the env command in the linker container shows envi‐
1371 ronment variables
1372 with the LT (alias) context (LT_)
1373
1374
1375 # env
1376 HOSTNAME=668231cb0978
1377 TERM=xterm
1378 LT_PORT_80_TCP=tcp://172.17.0.3:80
1379 LT_PORT_80_TCP_PORT=80
1380 LT_PORT_80_TCP_PROTO=tcp
1381 LT_PORT=tcp://172.17.0.3:80
1382 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
1383 PWD=/
1384 LT_NAME=/linker/lt
1385 SHLVL=1
1386 HOME=/
1387 LT_PORT_80_TCP_ADDR=172.17.0.3
1388 _=/usr/bin/env
1389
1390
1391
1392 When linking two containers Docker will use the exposed ports of the
1393 container to create a secure tunnel for the parent to access.
1394
1395
1396 If a container is connected to the default bridge network and linked
1397 with other containers, then the container's /etc/hosts file is updated
1398 with the linked container's name.
1399
1400
1401 Note Since Docker may live update the container's /etc/hosts
1402 file, there may be situations when processes inside the con‐
1403 tainer can end up reading an empty or incomplete /etc/hosts
1404 file. In most cases, retrying the read again should fix the
1405 problem.
1406
1407
1408
1410 The exposed port of an application can be mapped to a host port using
1411 the -p flag. For example, an httpd port 80 can be mapped to the host
1412 port 8080 using the following:
1413
1414
1415 # docker run -p 8080:80 -d -i -t fedora/httpd
1416
1417
1418
1420 Many applications require the sharing of persistent data across several
1421 containers. Docker allows you to create a Data Volume Container that
1422 other containers can mount from. For example, create a named container
1423 that contains directories /var/volume1 and /tmp/volume2. The image will
1424 need to contain these directories so a couple of RUN mkdir instructions
1425 might be required for you fedora-data image:
1426
1427
1428 # docker run --name=data -v /var/volume1 -v /tmp/volume2 -i -t fedora-data true
1429 # docker run --volumes-from=data --name=fedora-container1 -i -t fedora bash
1430
1431
1432
1433 Multiple --volumes-from parameters will bring together multiple data
1434 volumes from multiple containers. And it's possible to mount the vol‐
1435 umes that came from the DATA container in yet another container via the
1436 fedora-container1 intermediary container, allowing to abstract the
1437 actual data source from users of that data:
1438
1439
1440 # docker run --volumes-from=fedora-container1 --name=fedora-container2 -i -t fedora bash
1441
1442
1443
1445 To mount a host directory as a container volume, specify the absolute
1446 path to the directory and the absolute path for the container directory
1447 separated by a colon:
1448
1449
1450 # docker run -v /var/db:/data1 -i -t fedora bash
1451
1452
1453
1454 When using SELinux, be aware that the host has no knowledge of con‐
1455 tainer SELinux policy. Therefore, in the above example, if SELinux pol‐
1456 icy is enforced, the /var/db directory is not writable to the con‐
1457 tainer. A "Permission Denied" message will occur and an avc: message in
1458 the host's syslog.
1459
1460
1461 To work around this, at time of writing this man page, the following
1462 command needs to be run in order for the proper SELinux policy type
1463 label to be attached to the host directory:
1464
1465
1466 # chcon -Rt svirt_sandbox_file_t /var/db
1467
1468
1469
1470 Now, writing to the /data1 volume in the container will be allowed and
1471 the changes will also be reflected on the host in /var/db.
1472
1473
1475 You can override the default labeling scheme for each container by
1476 specifying the --security-opt flag. For example, you can specify the
1477 MCS/MLS level, a requirement for MLS systems. Specifying the level in
1478 the following command allows you to share the same content between con‐
1479 tainers.
1480
1481
1482 # docker run --security-opt label=level:s0:c100,c200 -i -t fedora bash
1483
1484
1485
1486 An MLS example might be:
1487
1488
1489 # docker run --security-opt label=level:TopSecret -i -t rhel7 bash
1490
1491
1492
1493 To disable the security labeling for this container versus running with
1494 the --permissive flag, use the following command:
1495
1496
1497 # docker run --security-opt label=disable -i -t fedora bash
1498
1499
1500
1501 If you want a tighter security policy on the processes within a con‐
1502 tainer, you can specify an alternate type for the container. You could
1503 run a container that is only allowed to listen on Apache ports by exe‐
1504 cuting the following command:
1505
1506
1507 # docker run --security-opt label=type:svirt_apache_t -i -t centos bash
1508
1509
1510
1511 Note:
1512
1513
1514 You would have to write policy defining a svirt_apache_t type.
1515
1516
1518 If you want to set /dev/sda device weight to 200, you can specify the
1519 device weight by --blkio-weight-device flag. Use the following command:
1520
1521
1522 # docker run -it --blkio-weight-device "/dev/sda:200" ubuntu
1523
1524
1525
1527 This option is useful in situations where you are running Docker con‐
1528 tainers on Microsoft Windows. The --isolation <value> option sets a
1529 container's isolation technology. On Linux, the only supported is the
1530 default option which uses Linux namespaces. These two commands are
1531 equivalent on Linux:
1532
1533
1534 $ docker run -d busybox top
1535 $ docker run -d --isolation default busybox top
1536
1537
1538
1539 On Microsoft Windows, can take any of these values:
1540
1541
1542 · default: Use the value specified by the Docker daemon's
1543 --exec-opt . If the daemon does not specify an isolation tech‐
1544 nology, Microsoft Windows uses process as its default value.
1545
1546 · process: Namespace isolation only.
1547
1548 · hyperv: Hyper-V hypervisor partition-based isolation.
1549
1550
1551
1552 In practice, when running on Microsoft Windows without a daemon option
1553 set, these two commands are equivalent:
1554
1555
1556 $ docker run -d --isolation default busybox top
1557 $ docker run -d --isolation process busybox top
1558
1559
1560
1561 If you have set the --exec-opt isolation=hyperv option on the Docker
1562 daemon, any of these commands also result in hyperv isolation:
1563
1564
1565 $ docker run -d --isolation default busybox top
1566 $ docker run -d --isolation hyperv busybox top
1567
1568
1569
1571 The --sysctl sets namespaced kernel parameters (sysctls) in the con‐
1572 tainer. For example, to turn on IP forwarding in the containers network
1573 namespace, run this command:
1574
1575
1576 $ docker run --sysctl net.ipv4.ip_forward=1 someimage
1577
1578
1579
1580 Note:
1581
1582
1583 Not all sysctls are namespaced. Docker does not support changing
1584 sysctls inside of a container that also modify the host system. As the
1585 kernel evolves we expect to see more sysctls become namespaced.
1586
1587
1588 See the definition of the --sysctl option above for the current list of
1589 supported sysctls.
1590
1591
1592
1594 April 2014, Originally compiled by William Henry (whenry at redhat dot
1595 com) based on docker.com source material and internal work. June 2014,
1596 updated by Sven Dowideit SvenDowideit@home.org.au ⟨mailto:Sven‐
1597 Dowideit@home.org.au⟩ July 2014, updated by Sven Dowideit Sven‐
1598 Dowideit@home.org.au ⟨mailto:SvenDowideit@home.org.au⟩ November 2015,
1599 updated by Sally O'Malley somalley@redhat.com ⟨mailto:somalley@red‐
1600 hat.com⟩
1601
1602
1603
1604Manuals User DOCKER(1)(Docker)