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