github.com/hustcat/docker@v1.3.3-0.20160314103604-901c67a8eeab/man/docker-run.1.md (about) 1 % DOCKER(1) Docker User Manuals 2 % Docker Community 3 % JUNE 2014 4 # NAME 5 docker-run - Run a command in a new container 6 7 # SYNOPSIS 8 **docker run** 9 [**-a**|**--attach**[=*[]*]] 10 [**--add-host**[=*[]*]] 11 [**--blkio-weight**[=*[BLKIO-WEIGHT]*]] 12 [**--blkio-weight-device**[=*[]*]] 13 [**--cpu-shares**[=*0*]] 14 [**--cap-add**[=*[]*]] 15 [**--cap-drop**[=*[]*]] 16 [**--cgroup-parent**[=*CGROUP-PATH*]] 17 [**--cidfile**[=*CIDFILE*]] 18 [**--cpu-period**[=*0*]] 19 [**--cpu-quota**[=*0*]] 20 [**--cpuset-cpus**[=*CPUSET-CPUS*]] 21 [**--cpuset-mems**[=*CPUSET-MEMS*]] 22 [**-d**|**--detach**] 23 [**--detach-keys**[=*[]*]] 24 [**--device**[=*[]*]] 25 [**--device-read-bps**[=*[]*]] 26 [**--device-read-iops**[=*[]*]] 27 [**--device-write-bps**[=*[]*]] 28 [**--device-write-iops**[=*[]*]] 29 [**--dns**[=*[]*]] 30 [**--dns-opt**[=*[]*]] 31 [**--dns-search**[=*[]*]] 32 [**-e**|**--env**[=*[]*]] 33 [**--entrypoint**[=*ENTRYPOINT*]] 34 [**--env-file**[=*[]*]] 35 [**--expose**[=*[]*]] 36 [**--group-add**[=*[]*]] 37 [**-h**|**--hostname**[=*HOSTNAME*]] 38 [**--help**] 39 [**-i**|**--interactive**] 40 [**--ip**[=*IPv4-ADDRESS*]] 41 [**--ip6**[=*IPv6-ADDRESS*]] 42 [**--ipc**[=*IPC*]] 43 [**--isolation**[=*default*]] 44 [**--kernel-memory**[=*KERNEL-MEMORY*]] 45 [**-l**|**--label**[=*[]*]] 46 [**--label-file**[=*[]*]] 47 [**--link**[=*[]*]] 48 [**--log-driver**[=*[]*]] 49 [**--log-opt**[=*[]*]] 50 [**-m**|**--memory**[=*MEMORY*]] 51 [**--mac-address**[=*MAC-ADDRESS*]] 52 [**--memory-reservation**[=*MEMORY-RESERVATION*]] 53 [**--memory-swap**[=*LIMIT*]] 54 [**--memory-swappiness**[=*MEMORY-SWAPPINESS*]] 55 [**--name**[=*NAME*]] 56 [**--net**[=*"bridge"*]] 57 [**--net-alias**[=*[]*]] 58 [**--oom-kill-disable**] 59 [**--oom-score-adj**[=*0*]] 60 [**-P**|**--publish-all**] 61 [**-p**|**--publish**[=*[]*]] 62 [**--pid**[=*[]*]] 63 [**--pids-limit**[=*PIDS_LIMIT*]] 64 [**--privileged**] 65 [**--read-only**] 66 [**--restart**[=*RESTART*]] 67 [**--rm**] 68 [**--security-opt**[=*[]*]] 69 [**--stop-signal**[=*SIGNAL*]] 70 [**--shm-size**[=*[]*]] 71 [**--sig-proxy**[=*true*]] 72 [**-t**|**--tty**] 73 [**--tmpfs**[=*[CONTAINER-DIR[:<OPTIONS>]*]] 74 [**-u**|**--user**[=*USER*]] 75 [**--ulimit**[=*[]*]] 76 [**--uts**[=*[]*]] 77 [**-v**|**--volume**[=*[[HOST-DIR:]CONTAINER-DIR[:OPTIONS]]*]] 78 [**--volume-driver**[=*DRIVER*]] 79 [**--volumes-from**[=*[]*]] 80 [**-w**|**--workdir**[=*WORKDIR*]] 81 IMAGE [COMMAND] [ARG...] 82 83 # DESCRIPTION 84 85 Run a process in a new container. **docker run** starts a process with its own 86 file system, its own networking, and its own isolated process tree. The IMAGE 87 which starts the process may define defaults related to the process that will be 88 run in the container, the networking to expose, and more, but **docker run** 89 gives final control to the operator or administrator who starts the container 90 from the image. For that reason **docker run** has more options than any other 91 Docker command. 92 93 If the IMAGE is not already loaded then **docker run** will pull the IMAGE, and 94 all image dependencies, from the repository in the same way running **docker 95 pull** IMAGE, before it starts the container from that image. 96 97 # OPTIONS 98 **-a**, **--attach**=[] 99 Attach to STDIN, STDOUT or STDERR. 100 101 In foreground mode (the default when **-d** 102 is not specified), **docker run** can start the process in the container 103 and attach the console to the process’s standard input, output, and standard 104 error. It can even pretend to be a TTY (this is what most commandline 105 executables expect) and pass along signals. The **-a** option can be set for 106 each of stdin, stdout, and stderr. 107 108 **--add-host**=[] 109 Add a custom host-to-IP mapping (host:ip) 110 111 Add a line to /etc/hosts. The format is hostname:ip. The **--add-host** 112 option can be set multiple times. 113 114 **--blkio-weight**=*0* 115 Block IO weight (relative weight) accepts a weight value between 10 and 1000. 116 117 **--blkio-weight-device**=[] 118 Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`). 119 120 **--cpu-shares**=*0* 121 CPU shares (relative weight) 122 123 By default, all containers get the same proportion of CPU cycles. This proportion 124 can be modified by changing the container's CPU share weighting relative 125 to the weighting of all other running containers. 126 127 To modify the proportion from the default of 1024, use the **--cpu-shares** 128 flag to set the weighting to 2 or higher. 129 130 The proportion will only apply when CPU-intensive processes are running. 131 When tasks in one container are idle, other containers can use the 132 left-over CPU time. The actual amount of CPU time will vary depending on 133 the number of containers running on the system. 134 135 For example, consider three containers, one has a cpu-share of 1024 and 136 two others have a cpu-share setting of 512. When processes in all three 137 containers attempt to use 100% of CPU, the first container would receive 138 50% of the total CPU time. If you add a fourth container with a cpu-share 139 of 1024, the first container only gets 33% of the CPU. The remaining containers 140 receive 16.5%, 16.5% and 33% of the CPU. 141 142 On a multi-core system, the shares of CPU time are distributed over all CPU 143 cores. Even if a container is limited to less than 100% of CPU time, it can 144 use 100% of each individual CPU core. 145 146 For example, consider a system with more than three cores. If you start one 147 container **{C0}** with **-c=512** running one process, and another container 148 **{C1}** with **-c=1024** running two processes, this can result in the following 149 division of CPU shares: 150 151 PID container CPU CPU share 152 100 {C0} 0 100% of CPU0 153 101 {C1} 1 100% of CPU1 154 102 {C1} 2 100% of CPU2 155 156 **--cap-add**=[] 157 Add Linux capabilities 158 159 **--cap-drop**=[] 160 Drop Linux capabilities 161 162 **--cgroup-parent**="" 163 Path to cgroups under which the cgroup for the container will be created. If the path is not absolute, the path is considered to be relative to the cgroups path of the init process. Cgroups will be created if they do not already exist. 164 165 **--cidfile**="" 166 Write the container ID to the file 167 168 **--cpu-period**=*0* 169 Limit the CPU CFS (Completely Fair Scheduler) period 170 171 Limit the container's CPU usage. This flag tell the kernel to restrict the container's CPU usage to the period you specify. 172 173 **--cpuset-cpus**="" 174 CPUs in which to allow execution (0-3, 0,1) 175 176 **--cpuset-mems**="" 177 Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. 178 179 If you have four memory nodes on your system (0-3), use `--cpuset-mems=0,1` 180 then processes in your Docker container will only use memory from the first 181 two memory nodes. 182 183 **--cpu-quota**=*0* 184 Limit the CPU CFS (Completely Fair Scheduler) quota 185 186 Limit the container's CPU usage. By default, containers run with the full 187 CPU resource. This flag tell the kernel to restrict the container's CPU usage 188 to the quota you specify. 189 190 **-d**, **--detach**=*true*|*false* 191 Detached mode: run the container in the background and print the new container ID. The default is *false*. 192 193 At any time you can run **docker ps** in 194 the other shell to view a list of the running containers. You can reattach to a 195 detached container with **docker attach**. If you choose to run a container in 196 the detached mode, then you cannot use the **-rm** option. 197 198 When attached in the tty mode, you can detach from the container (and leave it 199 running) using a configurable key sequence. The default sequence is `CTRL-p CTRL-q`. 200 You configure the key sequence using the **--detach-keys** option or a configuration file. 201 See **config-json(5)** for documentation on using a configuration file. 202 203 **--detach-keys**="" 204 Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. 205 206 **--device**=[] 207 Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm) 208 209 **--device-read-bps**=[] 210 Limit read rate from a device (e.g. --device-read-bps=/dev/sda:1mb) 211 212 **--device-read-iops**=[] 213 Limit read rate from a device (e.g. --device-read-iops=/dev/sda:1000) 214 215 **--device-write-bps**=[] 216 Limit write rate to a device (e.g. --device-write-bps=/dev/sda:1mb) 217 218 **--device-write-iops**=[] 219 Limit write rate a a device (e.g. --device-write-iops=/dev/sda:1000) 220 221 **--dns-search**=[] 222 Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain) 223 224 **--dns-opt**=[] 225 Set custom DNS options 226 227 **--dns**=[] 228 Set custom DNS servers 229 230 This option can be used to override the DNS 231 configuration passed to the container. Typically this is necessary when the 232 host DNS configuration is invalid for the container (e.g., 127.0.0.1). When this 233 is the case the **--dns** flags is necessary for every run. 234 235 **-e**, **--env**=[] 236 Set environment variables 237 238 This option allows you to specify arbitrary 239 environment variables that are available for the process that will be launched 240 inside of the container. 241 242 **--entrypoint**="" 243 Overwrite the default ENTRYPOINT of the image 244 245 This option allows you to overwrite the default entrypoint of the image that 246 is set in the Dockerfile. The ENTRYPOINT of an image is similar to a COMMAND 247 because it specifies what executable to run when the container starts, but it is 248 (purposely) more difficult to override. The ENTRYPOINT gives a container its 249 default nature or behavior, so that when you set an ENTRYPOINT you can run the 250 container as if it were that binary, complete with default options, and you can 251 pass in more options via the COMMAND. But, sometimes an operator may want to run 252 something else inside the container, so you can override the default ENTRYPOINT 253 at runtime by using a **--entrypoint** and a string to specify the new 254 ENTRYPOINT. 255 256 **--env-file**=[] 257 Read in a line delimited file of environment variables 258 259 **--expose**=[] 260 Expose a port, or a range of ports (e.g. --expose=3300-3310) informs Docker 261 that the container listens on the specified network ports at runtime. Docker 262 uses this information to interconnect containers using links and to set up port 263 redirection on the host system. 264 265 **--group-add**=[] 266 Add additional groups to run as 267 268 **-h**, **--hostname**="" 269 Container host name 270 271 Sets the container host name that is available inside the container. 272 273 **--help** 274 Print usage statement 275 276 **-i**, **--interactive**=*true*|*false* 277 Keep STDIN open even if not attached. The default is *false*. 278 279 When set to true, keep stdin open even if not attached. The default is false. 280 281 **--ip**="" 282 Sets the container's interface IPv4 address (e.g. 172.23.0.9) 283 284 It can only be used in conjunction with **--net** for user-defined networks 285 286 **--ip6**="" 287 Sets the container's interface IPv6 address (e.g. 2001:db8::1b99) 288 289 It can only be used in conjunction with **--net** for user-defined networks 290 291 **--ipc**="" 292 Default is to create a private IPC namespace (POSIX SysV IPC) for the container 293 'container:<name|id>': reuses another container shared memory, semaphores and message queues 294 'host': use the host shared memory,semaphores and message queues inside the container. Note: the host mode gives the container full access to local shared memory and is therefore considered insecure. 295 296 **--isolation**="*default*" 297 Isolation specifies the type of isolation technology used by containers. 298 299 **-l**, **--label**=[] 300 Set metadata on the container (e.g., --label com.example.key=value) 301 302 **--kernel-memory**="" 303 Kernel memory limit (format: `<number>[<unit>]`, where unit = b, k, m or g) 304 305 Constrains the kernel memory available to a container. If a limit of 0 306 is specified (not using `--kernel-memory`), the container's kernel memory 307 is not limited. If you specify a limit, it may be rounded up to a multiple 308 of the operating system's page size and the value can be very large, 309 millions of trillions. 310 311 **--label-file**=[] 312 Read in a line delimited file of labels 313 314 **--link**=[] 315 Add link to another container in the form of <name or id>:alias or just <name or id> 316 in which case the alias will match the name 317 318 If the operator 319 uses **--link** when starting the new client container, then the client 320 container can access the exposed port via a private networking interface. Docker 321 will set some environment variables in the client container to help indicate 322 which interface and port to use. 323 324 **--log-driver**="*json-file*|*syslog*|*journald*|*gelf*|*fluentd*|*awslogs*|*splunk*|*etwlogs*|*gcplogs*|*none*" 325 Logging driver for container. Default is defined by daemon `--log-driver` flag. 326 **Warning**: the `docker logs` command works only for the `json-file` and 327 `journald` logging drivers. 328 329 **--log-opt**=[] 330 Logging driver specific options. 331 332 **-m**, **--memory**="" 333 Memory limit (format: <number>[<unit>], where unit = b, k, m or g) 334 335 Allows you to constrain the memory available to a container. If the host 336 supports swap memory, then the **-m** memory setting can be larger than physical 337 RAM. If a limit of 0 is specified (not using **-m**), the container's memory is 338 not limited. The actual limit may be rounded up to a multiple of the operating 339 system's page size (the value would be very large, that's millions of trillions). 340 341 **--memory-reservation**="" 342 Memory soft limit (format: <number>[<unit>], where unit = b, k, m or g) 343 344 After setting memory reservation, when the system detects memory contention 345 or low memory, containers are forced to restrict their consumption to their 346 reservation. So you should always set the value below **--memory**, otherwise the 347 hard limit will take precedence. By default, memory reservation will be the same 348 as memory limit. 349 350 **--memory-swap**="LIMIT" 351 A limit value equal to memory plus swap. Must be used with the **-m** 352 (**--memory**) flag. The swap `LIMIT` should always be larger than **-m** 353 (**--memory**) value. 354 355 The format of `LIMIT` is `<number>[<unit>]`. Unit can be `b` (bytes), 356 `k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you don't specify a 357 unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap. 358 359 **--mac-address**="" 360 Container MAC address (e.g. 92:d0:c6:0a:29:33) 361 362 Remember that the MAC address in an Ethernet network must be unique. 363 The IPv6 link-local address will be based on the device's MAC address 364 according to RFC4862. 365 366 **--name**="" 367 Assign a name to the container 368 369 The operator can identify a container in three ways: 370 UUID long identifier (“f78375b1c487e03c9438c729345e54db9d20cfa2ac1fc3494b6eb60872e74778”) 371 UUID short identifier (“f78375b1c487”) 372 Name (“jonah”) 373 374 The UUID identifiers come from the Docker daemon, and if a name is not assigned 375 to the container with **--name** then the daemon will also generate a random 376 string name. The name is useful when defining links (see **--link**) (or any 377 other place you need to identify a container). This works for both background 378 and foreground Docker containers. 379 380 **--net**="*bridge*" 381 Set the Network mode for the container 382 'bridge': create a network stack on the default Docker bridge 383 'none': no networking 384 'container:<name|id>': reuse another container's network stack 385 'host': use the Docker host network stack. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure. 386 '<network-name>|<network-id>': connect to a user-defined network 387 388 **--net-alias**=[] 389 Add network-scoped alias for the container 390 391 **--oom-kill-disable**=*true*|*false* 392 Whether to disable OOM Killer for the container or not. 393 394 **--oom-score-adj**="" 395 Tune the host's OOM preferences for containers (accepts -1000 to 1000) 396 397 **-P**, **--publish-all**=*true*|*false* 398 Publish all exposed ports to random ports on the host interfaces. The default is *false*. 399 400 When set to true publish all exposed ports to the host interfaces. The 401 default is false. If the operator uses -P (or -p) then Docker will make the 402 exposed port accessible on the host and the ports will be available to any 403 client that can reach the host. When using -P, Docker will bind any exposed 404 port to a random port on the host within an *ephemeral port range* defined by 405 `/proc/sys/net/ipv4/ip_local_port_range`. To find the mapping between the host 406 ports and the exposed ports, use `docker port`. 407 408 **-p**, **--publish**=[] 409 Publish a container's port, or range of ports, to the host. 410 411 Format: `ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort` 412 Both hostPort and containerPort can be specified as a range of ports. 413 When specifying ranges for both, the number of container ports in the range must match the number of host ports in the range. 414 (e.g., `docker run -p 1234-1236:1222-1224 --name thisWorks -t busybox` 415 but not `docker run -p 1230-1236:1230-1240 --name RangeContainerPortsBiggerThanRangeHostPorts -t busybox`) 416 With ip: `docker run -p 127.0.0.1:$HOSTPORT:$CONTAINERPORT --name CONTAINER -t someimage` 417 Use `docker port` to see the actual mapping: `docker port CONTAINER $CONTAINERPORT` 418 419 **--pid**=*host* 420 Set the PID mode for the container 421 **host**: use the host's PID namespace inside the container. 422 Note: the host mode gives the container full access to local PID and is therefore considered insecure. 423 424 **--pids-limit**="" 425 Tune the container's pids limit. Set `-1` to have unlimited pids for the container. 426 427 **--uts**=*host* 428 Set the UTS mode for the container 429 **host**: use the host's UTS namespace inside the container. 430 Note: the host mode gives the container access to changing the host's hostname and is therefore considered insecure. 431 432 **--privileged**=*true*|*false* 433 Give extended privileges to this container. The default is *false*. 434 435 By default, Docker containers are 436 “unprivileged” (=false) and cannot, for example, run a Docker daemon inside the 437 Docker container. This is because by default a container is not allowed to 438 access any devices. A “privileged” container is given access to all devices. 439 440 When the operator executes **docker run --privileged**, Docker will enable access 441 to all devices on the host as well as set some configuration in AppArmor to 442 allow the container nearly all the same access to the host as processes running 443 outside of a container on the host. 444 445 **--read-only**=*true*|*false* 446 Mount the container's root filesystem as read only. 447 448 By default a container will have its root filesystem writable allowing processes 449 to write files anywhere. By specifying the `--read-only` flag the container will have 450 its root filesystem mounted as read only prohibiting any writes. 451 452 **--restart**="*no*" 453 Restart policy to apply when a container exits (no, on-failure[:max-retry], always, unless-stopped). 454 455 **--rm**=*true*|*false* 456 Automatically remove the container when it exits (incompatible with -d). The default is *false*. 457 458 **--security-opt**=[] 459 Security Options 460 461 "label:user:USER" : Set the label user for the container 462 "label:role:ROLE" : Set the label role for the container 463 "label:type:TYPE" : Set the label type for the container 464 "label:level:LEVEL" : Set the label level for the container 465 "label:disable" : Turn off label confinement for the container 466 "no-new-privileges" : Disable container processes from gaining additional privileges 467 468 469 **--stop-signal**=*SIGTERM* 470 Signal to stop a container. Default is SIGTERM. 471 472 **--shm-size**="" 473 Size of `/dev/shm`. The format is `<number><unit>`. 474 `number` must be greater than `0`. Unit is optional and can be `b` (bytes), `k` (kilobytes), `m`(megabytes), or `g` (gigabytes). 475 If you omit the unit, the system uses bytes. If you omit the size entirely, the system uses `64m`. 476 477 **--sig-proxy**=*true*|*false* 478 Proxy received signals to the process (non-TTY mode only). SIGCHLD, SIGSTOP, and SIGKILL are not proxied. The default is *true*. 479 480 **--memory-swappiness**="" 481 Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100. 482 483 **-t**, **--tty**=*true*|*false* 484 Allocate a pseudo-TTY. The default is *false*. 485 486 When set to true Docker can allocate a pseudo-tty and attach to the standard 487 input of any container. This can be used, for example, to run a throwaway 488 interactive shell. The default is false. 489 490 The **-t** option is incompatible with a redirection of the docker client 491 standard input. 492 493 **--tmpfs**=[] Create a tmpfs mount 494 495 Mount a temporary filesystem (`tmpfs`) mount into a container, for example: 496 497 $ docker run -d --tmpfs /tmp:rw,size=787448k,mode=1777 my_image 498 499 This command mounts a `tmpfs` at `/tmp` within the container. The supported mount 500 options are the same as the Linux default `mount` flags. If you do not specify 501 any options, the systems uses the following options: 502 `rw,noexec,nosuid,nodev,size=65536k`. 503 504 **-u**, **--user**="" 505 Sets the username or UID used and optionally the groupname or GID for the specified command. 506 507 The followings examples are all valid: 508 --user [user | user:group | uid | uid:gid | user:gid | uid:group ] 509 510 Without this argument the command will be run as root in the container. 511 512 **--ulimit**=[] 513 Ulimit options 514 515 **-v**|**--volume**[=*[[HOST-DIR:]CONTAINER-DIR[:OPTIONS]]*] 516 Create a bind mount. If you specify, ` -v /HOST-DIR:/CONTAINER-DIR`, Docker 517 bind mounts `/HOST-DIR` in the host to `/CONTAINER-DIR` in the Docker 518 container. If 'HOST-DIR' is omitted, Docker automatically creates the new 519 volume on the host. The `OPTIONS` are a comma delimited list and can be: 520 521 * [rw|ro] 522 * [z|Z] 523 * [`[r]shared`|`[r]slave`|`[r]private`] 524 525 The `CONTAINER-DIR` must be an absolute path such as `/src/docs`. The `HOST-DIR` 526 can be an absolute path or a `name` value. A `name` value must start with an 527 alphanumeric character, followed by `a-z0-9`, `_` (underscore), `.` (period) or 528 `-` (hyphen). An absolute path starts with a `/` (forward slash). 529 530 If you supply a `HOST-DIR` that is an absolute path, Docker bind-mounts to the 531 path you specify. If you supply a `name`, Docker creates a named volume by that 532 `name`. For example, you can specify either `/foo` or `foo` for a `HOST-DIR` 533 value. If you supply the `/foo` value, Docker creates a bind-mount. If you 534 supply the `foo` specification, Docker creates a named volume. 535 536 You can specify multiple **-v** options to mount one or more mounts to a 537 container. To use these same mounts in other containers, specify the 538 **--volumes-from** option also. 539 540 You can add `:ro` or `:rw` suffix to a volume to mount it read-only or 541 read-write mode, respectively. By default, the volumes are mounted read-write. 542 See examples. 543 544 Labeling systems like SELinux require that proper labels are placed on volume 545 content mounted into a container. Without a label, the security system might 546 prevent the processes running inside the container from using the content. By 547 default, Docker does not change the labels set by the OS. 548 549 To change a label in the container context, you can add either of two suffixes 550 `:z` or `:Z` to the volume mount. These suffixes tell Docker to relabel file 551 objects on the shared volumes. The `z` option tells Docker that two containers 552 share the volume content. As a result, Docker labels the content with a shared 553 content label. Shared volume labels allow all containers to read/write content. 554 The `Z` option tells Docker to label the content with a private unshared label. 555 Only the current container can use a private volume. 556 557 By default bind mounted volumes are `private`. That means any mounts done 558 inside container will not be visible on host and vice-a-versa. One can change 559 this behavior by specifying a volume mount propagation property. Making a 560 volume `shared` mounts done under that volume inside container will be 561 visible on host and vice-a-versa. Making a volume `slave` enables only one 562 way mount propagation and that is mounts done on host under that volume 563 will be visible inside container but not the other way around. 564 565 To control mount propagation property of volume one can use `:[r]shared`, 566 `:[r]slave` or `:[r]private` propagation flag. Propagation property can 567 be specified only for bind mounted volumes and not for internal volumes or 568 named volumes. For mount propagation to work source mount point (mount point 569 where source dir is mounted on) has to have right propagation properties. For 570 shared volumes, source mount point has to be shared. And for slave volumes, 571 source mount has to be either shared or slave. 572 573 Use `df <source-dir>` to figure out the source mount and then use 574 `findmnt -o TARGET,PROPAGATION <source-mount-dir>` to figure out propagation 575 properties of source mount. If `findmnt` utility is not available, then one 576 can look at mount entry for source mount point in `/proc/self/mountinfo`. Look 577 at `optional fields` and see if any propagaion properties are specified. 578 `shared:X` means mount is `shared`, `master:X` means mount is `slave` and if 579 nothing is there that means mount is `private`. 580 581 To change propagation properties of a mount point use `mount` command. For 582 example, if one wants to bind mount source directory `/foo` one can do 583 `mount --bind /foo /foo` and `mount --make-private --make-shared /foo`. This 584 will convert /foo into a `shared` mount point. Alternatively one can directly 585 change propagation properties of source mount. Say `/` is source mount for 586 `/foo`, then use `mount --make-shared /` to convert `/` into a `shared` mount. 587 588 > **Note**: 589 > When using systemd to manage the Docker daemon's start and stop, in the systemd 590 > unit file there is an option to control mount propagation for the Docker daemon 591 > itself, called `MountFlags`. The value of this setting may cause Docker to not 592 > see mount propagation changes made on the mount point. For example, if this value 593 > is `slave`, you may not be able to use the `shared` or `rshared` propagation on 594 > a volume. 595 596 **--volume-driver**="" 597 Container's volume driver. This driver creates volumes specified either from 598 a Dockerfile's `VOLUME` instruction or from the `docker run -v` flag. 599 See **docker-volume-create(1)** for full details. 600 601 **--volumes-from**=[] 602 Mount volumes from the specified container(s) 603 604 Mounts already mounted volumes from a source container onto another 605 container. You must supply the source's container-id. To share 606 a volume, use the **--volumes-from** option when running 607 the target container. You can share volumes even if the source container 608 is not running. 609 610 By default, Docker mounts the volumes in the same mode (read-write or 611 read-only) as it is mounted in the source container. Optionally, you 612 can change this by suffixing the container-id with either the `:ro` or 613 `:rw ` keyword. 614 615 If the location of the volume from the source container overlaps with 616 data residing on a target container, then the volume hides 617 that data on the target. 618 619 **-w**, **--workdir**="" 620 Working directory inside the container 621 622 The default working directory for 623 running binaries within a container is the root directory (/). The developer can 624 set a different default with the Dockerfile WORKDIR instruction. The operator 625 can override the working directory by using the **-w** option. 626 627 # Exit Status 628 629 The exit code from `docker run` gives information about why the container 630 failed to run or why it exited. When `docker run` exits with a non-zero code, 631 the exit codes follow the `chroot` standard, see below: 632 633 **_125_** if the error is with Docker daemon **_itself_** 634 635 $ docker run --foo busybox; echo $? 636 # flag provided but not defined: --foo 637 See 'docker run --help'. 638 125 639 640 **_126_** if the **_contained command_** cannot be invoked 641 642 $ docker run busybox /etc; echo $? 643 # exec: "/etc": permission denied 644 docker: Error response from daemon: Contained command could not be invoked 645 126 646 647 **_127_** if the **_contained command_** cannot be found 648 649 $ docker run busybox foo; echo $? 650 # exec: "foo": executable file not found in $PATH 651 docker: Error response from daemon: Contained command not found or does not exist 652 127 653 654 **_Exit code_** of **_contained command_** otherwise 655 656 $ docker run busybox /bin/sh -c 'exit 3' 657 # 3 658 659 # EXAMPLES 660 661 ## Running container in read-only mode 662 663 During container image development, containers often need to write to the image 664 content. Installing packages into /usr, for example. In production, 665 applications seldom need to write to the image. Container applications write 666 to volumes if they need to write to file systems at all. Applications can be 667 made more secure by running them in read-only mode using the --read-only switch. 668 This protects the containers image from modification. Read only containers may 669 still need to write temporary data. The best way to handle this is to mount 670 tmpfs directories on /run and /tmp. 671 672 # docker run --read-only --tmpfs /run --tmpfs /tmp -i -t fedora /bin/bash 673 674 ## Exposing log messages from the container to the host's log 675 676 If you want messages that are logged in your container to show up in the host's 677 syslog/journal then you should bind mount the /dev/log directory as follows. 678 679 # docker run -v /dev/log:/dev/log -i -t fedora /bin/bash 680 681 From inside the container you can test this by sending a message to the log. 682 683 (bash)# logger "Hello from my container" 684 685 Then exit and check the journal. 686 687 # exit 688 689 # journalctl -b | grep Hello 690 691 This should list the message sent to logger. 692 693 ## Attaching to one or more from STDIN, STDOUT, STDERR 694 695 If you do not specify -a then Docker will attach everything (stdin,stdout,stderr) 696 . You can specify to which of the three standard streams (stdin, stdout, stderr) 697 you’d like to connect instead, as in: 698 699 # docker run -a stdin -a stdout -i -t fedora /bin/bash 700 701 ## Sharing IPC between containers 702 703 Using shm_server.c available here: https://www.cs.cf.ac.uk/Dave/C/node27.html 704 705 Testing `--ipc=host` mode: 706 707 Host shows a shared memory segment with 7 pids attached, happens to be from httpd: 708 709 ``` 710 $ sudo ipcs -m 711 712 ------ Shared Memory Segments -------- 713 key shmid owner perms bytes nattch status 714 0x01128e25 0 root 600 1000 7 715 ``` 716 717 Now run a regular container, and it correctly does NOT see the shared memory segment from the host: 718 719 ``` 720 $ docker run -it shm ipcs -m 721 722 ------ Shared Memory Segments -------- 723 key shmid owner perms bytes nattch status 724 ``` 725 726 Run a container with the new `--ipc=host` option, and it now sees the shared memory segment from the host httpd: 727 728 ``` 729 $ docker run -it --ipc=host shm ipcs -m 730 731 ------ Shared Memory Segments -------- 732 key shmid owner perms bytes nattch status 733 0x01128e25 0 root 600 1000 7 734 ``` 735 Testing `--ipc=container:CONTAINERID` mode: 736 737 Start a container with a program to create a shared memory segment: 738 ``` 739 $ docker run -it shm bash 740 $ sudo shm/shm_server & 741 $ sudo ipcs -m 742 743 ------ Shared Memory Segments -------- 744 key shmid owner perms bytes nattch status 745 0x0000162e 0 root 666 27 1 746 ``` 747 Create a 2nd container correctly shows no shared memory segment from 1st container: 748 ``` 749 $ docker run shm ipcs -m 750 751 ------ Shared Memory Segments -------- 752 key shmid owner perms bytes nattch status 753 ``` 754 755 Create a 3rd container using the new --ipc=container:CONTAINERID option, now it shows the shared memory segment from the first: 756 757 ``` 758 $ docker run -it --ipc=container:ed735b2264ac shm ipcs -m 759 $ sudo ipcs -m 760 761 ------ Shared Memory Segments -------- 762 key shmid owner perms bytes nattch status 763 0x0000162e 0 root 666 27 1 764 ``` 765 766 ## Linking Containers 767 768 > **Note**: This section describes linking between containers on the 769 > default (bridge) network, also known as "legacy links". Using `--link` 770 > on user-defined networks uses the DNS-based discovery, which does not add 771 > entries to `/etc/hosts`, and does not set environment variables for 772 > discovery. 773 774 The link feature allows multiple containers to communicate with each other. For 775 example, a container whose Dockerfile has exposed port 80 can be run and named 776 as follows: 777 778 # docker run --name=link-test -d -i -t fedora/httpd 779 780 A second container, in this case called linker, can communicate with the httpd 781 container, named link-test, by running with the **--link=<name>:<alias>** 782 783 # docker run -t -i --link=link-test:lt --name=linker fedora /bin/bash 784 785 Now the container linker is linked to container link-test with the alias lt. 786 Running the **env** command in the linker container shows environment variables 787 with the LT (alias) context (**LT_**) 788 789 # env 790 HOSTNAME=668231cb0978 791 TERM=xterm 792 LT_PORT_80_TCP=tcp://172.17.0.3:80 793 LT_PORT_80_TCP_PORT=80 794 LT_PORT_80_TCP_PROTO=tcp 795 LT_PORT=tcp://172.17.0.3:80 796 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 797 PWD=/ 798 LT_NAME=/linker/lt 799 SHLVL=1 800 HOME=/ 801 LT_PORT_80_TCP_ADDR=172.17.0.3 802 _=/usr/bin/env 803 804 When linking two containers Docker will use the exposed ports of the container 805 to create a secure tunnel for the parent to access. 806 807 If a container is connected to the default bridge network and `linked` 808 with other containers, then the container's `/etc/hosts` file is updated 809 with the linked container's name. 810 811 > **Note** Since Docker may live update the container’s `/etc/hosts` file, there 812 may be situations when processes inside the container can end up reading an 813 empty or incomplete `/etc/hosts` file. In most cases, retrying the read again 814 should fix the problem. 815 816 817 ## Mapping Ports for External Usage 818 819 The exposed port of an application can be mapped to a host port using the **-p** 820 flag. For example, a httpd port 80 can be mapped to the host port 8080 using the 821 following: 822 823 # docker run -p 8080:80 -d -i -t fedora/httpd 824 825 ## Creating and Mounting a Data Volume Container 826 827 Many applications require the sharing of persistent data across several 828 containers. Docker allows you to create a Data Volume Container that other 829 containers can mount from. For example, create a named container that contains 830 directories /var/volume1 and /tmp/volume2. The image will need to contain these 831 directories so a couple of RUN mkdir instructions might be required for you 832 fedora-data image: 833 834 # docker run --name=data -v /var/volume1 -v /tmp/volume2 -i -t fedora-data true 835 # docker run --volumes-from=data --name=fedora-container1 -i -t fedora bash 836 837 Multiple --volumes-from parameters will bring together multiple data volumes from 838 multiple containers. And it's possible to mount the volumes that came from the 839 DATA container in yet another container via the fedora-container1 intermediary 840 container, allowing to abstract the actual data source from users of that data: 841 842 # docker run --volumes-from=fedora-container1 --name=fedora-container2 -i -t fedora bash 843 844 ## Mounting External Volumes 845 846 To mount a host directory as a container volume, specify the absolute path to 847 the directory and the absolute path for the container directory separated by a 848 colon: 849 850 # docker run -v /var/db:/data1 -i -t fedora bash 851 852 When using SELinux, be aware that the host has no knowledge of container SELinux 853 policy. Therefore, in the above example, if SELinux policy is enforced, the 854 `/var/db` directory is not writable to the container. A "Permission Denied" 855 message will occur and an avc: message in the host's syslog. 856 857 858 To work around this, at time of writing this man page, the following command 859 needs to be run in order for the proper SELinux policy type label to be attached 860 to the host directory: 861 862 # chcon -Rt svirt_sandbox_file_t /var/db 863 864 865 Now, writing to the /data1 volume in the container will be allowed and the 866 changes will also be reflected on the host in /var/db. 867 868 ## Using alternative security labeling 869 870 You can override the default labeling scheme for each container by specifying 871 the `--security-opt` flag. For example, you can specify the MCS/MLS level, a 872 requirement for MLS systems. Specifying the level in the following command 873 allows you to share the same content between containers. 874 875 # docker run --security-opt label:level:s0:c100,c200 -i -t fedora bash 876 877 An MLS example might be: 878 879 # docker run --security-opt label:level:TopSecret -i -t rhel7 bash 880 881 To disable the security labeling for this container versus running with the 882 `--permissive` flag, use the following command: 883 884 # docker run --security-opt label:disable -i -t fedora bash 885 886 If you want a tighter security policy on the processes within a container, 887 you can specify an alternate type for the container. You could run a container 888 that is only allowed to listen on Apache ports by executing the following 889 command: 890 891 # docker run --security-opt label:type:svirt_apache_t -i -t centos bash 892 893 Note: 894 895 You would have to write policy defining a `svirt_apache_t` type. 896 897 ## Setting device weight 898 899 If you want to set `/dev/sda` device weight to `200`, you can specify the device 900 weight by `--blkio-weight-device` flag. Use the following command: 901 902 # docker run -it --blkio-weight-device "/dev/sda:200" ubuntu 903 904 ## Specify isolation technology for container (--isolation) 905 906 This option is useful in situations where you are running Docker containers on 907 Microsoft Windows. The `--isolation <value>` option sets a container's isolation 908 technology. On Linux, the only supported is the `default` option which uses 909 Linux namespaces. These two commands are equivalent on Linux: 910 911 ``` 912 $ docker run -d busybox top 913 $ docker run -d --isolation default busybox top 914 ``` 915 916 On Microsoft Windows, can take any of these values: 917 918 * `default`: Use the value specified by the Docker daemon's `--exec-opt` . If the `daemon` does not specify an isolation technology, Microsoft Windows uses `process` as its default value. 919 * `process`: Namespace isolation only. 920 * `hyperv`: Hyper-V hypervisor partition-based isolation. 921 922 In practice, when running on Microsoft Windows without a `daemon` option set, these two commands are equivalent: 923 924 ``` 925 $ docker run -d --isolation default busybox top 926 $ docker run -d --isolation process busybox top 927 ``` 928 929 If you have set the `--exec-opt isolation=hyperv` option on the Docker `daemon`, any of these commands also result in `hyperv` isolation: 930 931 ``` 932 $ docker run -d --isolation default busybox top 933 $ docker run -d --isolation hyperv busybox top 934 ``` 935 936 # HISTORY 937 April 2014, Originally compiled by William Henry (whenry at redhat dot com) 938 based on docker.com source material and internal work. 939 June 2014, updated by Sven Dowideit <SvenDowideit@home.org.au> 940 July 2014, updated by Sven Dowideit <SvenDowideit@home.org.au> 941 November 2015, updated by Sally O'Malley <somalley@redhat.com>