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