github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/docs/reference/commandline/run.md (about) 1 <!--[metadata]> 2 +++ 3 title = "run" 4 description = "The run command description and usage" 5 keywords = ["run, command, container"] 6 [menu.main] 7 parent = "smn_cli" 8 +++ 9 <![end-metadata]--> 10 11 # run 12 13 ```markdown 14 Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] 15 16 Run a command in a new container 17 18 Options: 19 --add-host value Add a custom host-to-IP mapping (host:ip) (default []) 20 -a, --attach value Attach to STDIN, STDOUT or STDERR (default []) 21 --blkio-weight value Block IO (relative weight), between 10 and 1000 22 --blkio-weight-device value Block IO weight (relative device weight) (default []) 23 --cap-add value Add Linux capabilities (default []) 24 --cap-drop value Drop Linux capabilities (default []) 25 --cgroup-parent string Optional parent cgroup for the container 26 --cidfile string Write the container ID to the file 27 --cpu-percent int CPU percent (Windows only) 28 --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period 29 --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota 30 -c, --cpu-shares int CPU shares (relative weight) 31 --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) 32 --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) 33 -d, --detach Run container in background and print container ID 34 --detach-keys string Override the key sequence for detaching a container 35 --device value Add a host device to the container (default []) 36 --device-read-bps value Limit read rate (bytes per second) from a device (default []) 37 --device-read-iops value Limit read rate (IO per second) from a device (default []) 38 --device-write-bps value Limit write rate (bytes per second) to a device (default []) 39 --device-write-iops value Limit write rate (IO per second) to a device (default []) 40 --disable-content-trust Skip image verification (default true) 41 --dns value Set custom DNS servers (default []) 42 --dns-opt value Set DNS options (default []) 43 --dns-search value Set custom DNS search domains (default []) 44 --entrypoint string Overwrite the default ENTRYPOINT of the image 45 -e, --env value Set environment variables (default []) 46 --env-file value Read in a file of environment variables (default []) 47 --expose value Expose a port or a range of ports (default []) 48 --group-add value Add additional groups to join (default []) 49 --health-cmd string Command to run to check health 50 --health-interval duration Time between running the check 51 --health-retries int Consecutive failures needed to report unhealthy 52 --health-timeout duration Maximum time to allow one check to run 53 --help Print usage 54 -h, --hostname string Container host name 55 -i, --interactive Keep STDIN open even if not attached 56 --io-maxbandwidth string Maximum IO bandwidth limit for the system drive (Windows only) 57 (Windows only). The format is `<number><unit>`. 58 Unit is optional and can be `b` (bytes per second), 59 `k` (kilobytes per second), `m` (megabytes per second), 60 or `g` (gigabytes per second). If you omit the unit, 61 the system uses bytes per second. 62 --io-maxbandwidth and --io-maxiops are mutually exclusive options. 63 --io-maxiops uint Maximum IOps limit for the system drive (Windows only) 64 --ip string Container IPv4 address (e.g. 172.30.100.104) 65 --ip6 string Container IPv6 address (e.g. 2001:db8::33) 66 --ipc string IPC namespace to use 67 --isolation string Container isolation technology 68 --kernel-memory string Kernel memory limit 69 -l, --label value Set meta data on a container (default []) 70 --label-file value Read in a line delimited file of labels (default []) 71 --link value Add link to another container (default []) 72 --link-local-ip value Container IPv4/IPv6 link-local addresses (default []) 73 --log-driver string Logging driver for the container 74 --log-opt value Log driver options (default []) 75 --mac-address string Container MAC address (e.g. 92:d0:c6:0a:29:33) 76 -m, --memory string Memory limit 77 --memory-reservation string Memory soft limit 78 --memory-swap string Swap limit equal to memory plus swap: '-1' to enable unlimited swap 79 --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1) 80 --name string Assign a name to the container 81 --network-alias value Add network-scoped alias for the container (default []) 82 --network string Connect a container to a network 83 'bridge': create a network stack on the default Docker bridge 84 'none': no networking 85 'container:<name|id>': reuse another container's network stack 86 'host': use the Docker host network stack 87 '<network-name>|<network-id>': connect to a user-defined network 88 --no-healthcheck Disable any container-specified HEALTHCHECK 89 --oom-kill-disable Disable OOM Killer 90 --oom-score-adj int Tune host's OOM preferences (-1000 to 1000) 91 --pid string PID namespace to use 92 --pids-limit int Tune container pids limit (set -1 for unlimited) 93 --privileged Give extended privileges to this container 94 -p, --publish value Publish a container's port(s) to the host (default []) 95 -P, --publish-all Publish all exposed ports to random ports 96 --read-only Mount the container's root filesystem as read only 97 --restart string Restart policy to apply when a container exits (default "no") 98 Possible values are : no, on-failure[:max-retry], always, unless-stopped 99 --rm Automatically remove the container when it exits 100 --runtime string Runtime to use for this container 101 --security-opt value Security Options (default []) 102 --shm-size string Size of /dev/shm, default value is 64MB. 103 The format is `<number><unit>`. `number` must be greater than `0`. 104 Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), 105 or `g` (gigabytes). If you omit the unit, the system uses bytes. 106 --sig-proxy Proxy received signals to the process (default true) 107 --stop-signal string Signal to stop a container, SIGTERM by default (default "SIGTERM") 108 --storage-opt value Storage driver options for the container (default []) 109 --sysctl value Sysctl options (default map[]) 110 --tmpfs value Mount a tmpfs directory (default []) 111 -t, --tty Allocate a pseudo-TTY 112 --ulimit value Ulimit options (default []) 113 -u, --user string Username or UID (format: <name|uid>[:<group|gid>]) 114 --userns string User namespace to use 115 'host': Use the Docker host user namespace 116 '': Use the Docker daemon user namespace specified by `--userns-remap` option. 117 --uts string UTS namespace to use 118 -v, --volume value Bind mount a volume (default []). The format 119 is `[host-src:]container-dest[:<options>]`. 120 The comma-delimited `options` are [rw|ro], 121 [z|Z], [[r]shared|[r]slave|[r]private], and 122 [nocopy]. The 'host-src' is an absolute path 123 or a name value. 124 --volume-driver string Optional volume driver for the container 125 --volumes-from value Mount volumes from the specified container(s) (default []) 126 -w, --workdir string Working directory inside the container 127 ``` 128 129 The `docker run` command first `creates` a writeable container layer over the 130 specified image, and then `starts` it using the specified command. That is, 131 `docker run` is equivalent to the API `/containers/create` then 132 `/containers/(id)/start`. A stopped container can be restarted with all its 133 previous changes intact using `docker start`. See `docker ps -a` to view a list 134 of all containers. 135 136 The `docker run` command can be used in combination with `docker commit` to 137 [*change the command that a container runs*](commit.md). There is additional detailed information about `docker run` in the [Docker run reference](../run.md). 138 139 For information on connecting a container to a network, see the ["*Docker network overview*"](../../userguide/networking/index.md). 140 141 ## Examples 142 143 ### Assign name and allocate pseudo-TTY (--name, -it) 144 145 $ docker run --name test -it debian 146 root@d6c0fe130dba:/# exit 13 147 $ echo $? 148 13 149 $ docker ps -a | grep test 150 d6c0fe130dba debian:7 "/bin/bash" 26 seconds ago Exited (13) 17 seconds ago test 151 152 This example runs a container named `test` using the `debian:latest` 153 image. The `-it` instructs Docker to allocate a pseudo-TTY connected to 154 the container's stdin; creating an interactive `bash` shell in the container. 155 In the example, the `bash` shell is quit by entering 156 `exit 13`. This exit code is passed on to the caller of 157 `docker run`, and is recorded in the `test` container's metadata. 158 159 ### Capture container ID (--cidfile) 160 161 $ docker run --cidfile /tmp/docker_test.cid ubuntu echo "test" 162 163 This will create a container and print `test` to the console. The `cidfile` 164 flag makes Docker attempt to create a new file and write the container ID to it. 165 If the file exists already, Docker will return an error. Docker will close this 166 file when `docker run` exits. 167 168 ### Full container capabilities (--privileged) 169 170 $ docker run -t -i --rm ubuntu bash 171 root@bc338942ef20:/# mount -t tmpfs none /mnt 172 mount: permission denied 173 174 This will *not* work, because by default, most potentially dangerous kernel 175 capabilities are dropped; including `cap_sys_admin` (which is required to mount 176 filesystems). However, the `--privileged` flag will allow it to run: 177 178 $ docker run -t -i --privileged ubuntu bash 179 root@50e3f57e16e6:/# mount -t tmpfs none /mnt 180 root@50e3f57e16e6:/# df -h 181 Filesystem Size Used Avail Use% Mounted on 182 none 1.9G 0 1.9G 0% /mnt 183 184 The `--privileged` flag gives *all* capabilities to the container, and it also 185 lifts all the limitations enforced by the `device` cgroup controller. In other 186 words, the container can then do almost everything that the host can do. This 187 flag exists to allow special use-cases, like running Docker within Docker. 188 189 ### Set working directory (-w) 190 191 $ docker run -w /path/to/dir/ -i -t ubuntu pwd 192 193 The `-w` lets the command being executed inside directory given, here 194 `/path/to/dir/`. If the path does not exist it is created inside the container. 195 196 ### Set storage driver options per container 197 198 $ docker run -it --storage-opt size=120G fedora /bin/bash 199 200 This (size) will allow to set the container rootfs size to 120G at creation time. 201 User cannot pass a size less than the Default BaseFS Size. This option is only 202 available for the `devicemapper`, `btrfs`, `windowsfilter`, and `zfs` graph drivers. 203 204 ### Mount tmpfs (--tmpfs) 205 206 $ docker run -d --tmpfs /run:rw,noexec,nosuid,size=65536k my_image 207 208 The `--tmpfs` flag mounts an empty tmpfs into the container with the `rw`, 209 `noexec`, `nosuid`, `size=65536k` options. 210 211 ### Mount volume (-v, --read-only) 212 213 $ docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd 214 215 The `-v` flag mounts the current working directory into the container. The `-w` 216 lets the command being executed inside the current working directory, by 217 changing into the directory to the value returned by `pwd`. So this 218 combination executes the command using the container, but inside the 219 current working directory. 220 221 $ docker run -v /doesnt/exist:/foo -w /foo -i -t ubuntu bash 222 223 When the host directory of a bind-mounted volume doesn't exist, Docker 224 will automatically create this directory on the host for you. In the 225 example above, Docker will create the `/doesnt/exist` 226 folder before starting your container. 227 228 $ docker run --read-only -v /icanwrite busybox touch /icanwrite/here 229 230 Volumes can be used in combination with `--read-only` to control where 231 a container writes files. The `--read-only` flag mounts the container's root 232 filesystem as read only prohibiting writes to locations other than the 233 specified volumes for the container. 234 235 $ docker run -t -i -v /var/run/docker.sock:/var/run/docker.sock -v /path/to/static-docker-binary:/usr/bin/docker busybox sh 236 237 By bind-mounting the docker unix socket and statically linked docker 238 binary (refer to [get the linux binary]( 239 ../../installation/binaries.md#get-the-linux-binary)), 240 you give the container the full access to create and manipulate the host's 241 Docker daemon. 242 243 For in-depth information about volumes, refer to [manage data in containers](../../tutorials/dockervolumes.md) 244 245 ### Publish or expose port (-p, --expose) 246 247 $ docker run -p 127.0.0.1:80:8080 ubuntu bash 248 249 This binds port `8080` of the container to port `80` on `127.0.0.1` of the host 250 machine. The [Docker User 251 Guide](../../userguide/networking/default_network/dockerlinks.md) 252 explains in detail how to manipulate ports in Docker. 253 254 $ docker run --expose 80 ubuntu bash 255 256 This exposes port `80` of the container without publishing the port to the host 257 system's interfaces. 258 259 ### Set environment variables (-e, --env, --env-file) 260 261 $ docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash 262 263 This sets simple (non-array) environmental variables in the container. For 264 illustration all three 265 flags are shown here. Where `-e`, `--env` take an environment variable and 266 value, or if no `=` is provided, then that variable's current value, set via 267 `export`, is passed through (i.e. `$MYVAR1` from the host is set to `$MYVAR1` 268 in the container). When no `=` is provided and that variable is not defined 269 in the client's environment then that variable will be removed from the 270 container's list of environment variables. All three flags, `-e`, `--env` and 271 `--env-file` can be repeated. 272 273 Regardless of the order of these three flags, the `--env-file` are processed 274 first, and then `-e`, `--env` flags. This way, the `-e` or `--env` will 275 override variables as needed. 276 277 $ cat ./env.list 278 TEST_FOO=BAR 279 $ docker run --env TEST_FOO="This is a test" --env-file ./env.list busybox env | grep TEST_FOO 280 TEST_FOO=This is a test 281 282 The `--env-file` flag takes a filename as an argument and expects each line 283 to be in the `VAR=VAL` format, mimicking the argument passed to `--env`. Comment 284 lines need only be prefixed with `#` 285 286 An example of a file passed with `--env-file` 287 288 $ cat ./env.list 289 TEST_FOO=BAR 290 291 # this is a comment 292 TEST_APP_DEST_HOST=10.10.0.127 293 TEST_APP_DEST_PORT=8888 294 _TEST_BAR=FOO 295 TEST_APP_42=magic 296 helloWorld=true 297 123qwe=bar 298 org.spring.config=something 299 300 # pass through this variable from the caller 301 TEST_PASSTHROUGH 302 $ TEST_PASSTHROUGH=howdy docker run --env-file ./env.list busybox env 303 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 304 HOSTNAME=5198e0745561 305 TEST_FOO=BAR 306 TEST_APP_DEST_HOST=10.10.0.127 307 TEST_APP_DEST_PORT=8888 308 _TEST_BAR=FOO 309 TEST_APP_42=magic 310 helloWorld=true 311 TEST_PASSTHROUGH=howdy 312 HOME=/root 313 123qwe=bar 314 org.spring.config=something 315 316 $ docker run --env-file ./env.list busybox env 317 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 318 HOSTNAME=5198e0745561 319 TEST_FOO=BAR 320 TEST_APP_DEST_HOST=10.10.0.127 321 TEST_APP_DEST_PORT=8888 322 _TEST_BAR=FOO 323 TEST_APP_42=magic 324 helloWorld=true 325 TEST_PASSTHROUGH= 326 HOME=/root 327 123qwe=bar 328 org.spring.config=something 329 330 ### Set metadata on container (-l, --label, --label-file) 331 332 A label is a `key=value` pair that applies metadata to a container. To label a container with two labels: 333 334 $ docker run -l my-label --label com.example.foo=bar ubuntu bash 335 336 The `my-label` key doesn't specify a value so the label defaults to an empty 337 string(`""`). To add multiple labels, repeat the label flag (`-l` or `--label`). 338 339 The `key=value` must be unique to avoid overwriting the label value. If you 340 specify labels with identical keys but different values, each subsequent value 341 overwrites the previous. Docker uses the last `key=value` you supply. 342 343 Use the `--label-file` flag to load multiple labels from a file. Delimit each 344 label in the file with an EOL mark. The example below loads labels from a 345 labels file in the current directory: 346 347 $ docker run --label-file ./labels ubuntu bash 348 349 The label-file format is similar to the format for loading environment 350 variables. (Unlike environment variables, labels are not visible to processes 351 running inside a container.) The following example illustrates a label-file 352 format: 353 354 com.example.label1="a label" 355 356 # this is a comment 357 com.example.label2=another\ label 358 com.example.label3 359 360 You can load multiple label-files by supplying multiple `--label-file` flags. 361 362 For additional information on working with labels, see [*Labels - custom 363 metadata in Docker*](../../userguide/labels-custom-metadata.md) in the Docker User 364 Guide. 365 366 ### Connect a container to a network (--network) 367 368 When you start a container use the `--network` flag to connect it to a network. 369 This adds the `busybox` container to the `my-net` network. 370 371 ```bash 372 $ docker run -itd --network=my-net busybox 373 ``` 374 375 You can also choose the IP addresses for the container with `--ip` and `--ip6` 376 flags when you start the container on a user-defined network. 377 378 ```bash 379 $ docker run -itd --network=my-net --ip=10.10.9.75 busybox 380 ``` 381 382 If you want to add a running container to a network use the `docker network connect` subcommand. 383 384 You can connect multiple containers to the same network. Once connected, the 385 containers can communicate easily need only another container's IP address 386 or name. For `overlay` networks or custom plugins that support multi-host 387 connectivity, containers connected to the same multi-host network but launched 388 from different Engines can also communicate in this way. 389 390 **Note**: Service discovery is unavailable on the default bridge network. 391 Containers can communicate via their IP addresses by default. To communicate 392 by name, they must be linked. 393 394 You can disconnect a container from a network using the `docker network 395 disconnect` command. 396 397 ### Mount volumes from container (--volumes-from) 398 399 $ docker run --volumes-from 777f7dc92da7 --volumes-from ba8c0c54f0f2:ro -i -t ubuntu pwd 400 401 The `--volumes-from` flag mounts all the defined volumes from the referenced 402 containers. Containers can be specified by repetitions of the `--volumes-from` 403 argument. The container ID may be optionally suffixed with `:ro` or `:rw` to 404 mount the volumes in read-only or read-write mode, respectively. By default, 405 the volumes are mounted in the same mode (read write or read only) as 406 the reference container. 407 408 Labeling systems like SELinux require that proper labels are placed on volume 409 content mounted into a container. Without a label, the security system might 410 prevent the processes running inside the container from using the content. By 411 default, Docker does not change the labels set by the OS. 412 413 To change the label in the container context, you can add either of two suffixes 414 `:z` or `:Z` to the volume mount. These suffixes tell Docker to relabel file 415 objects on the shared volumes. The `z` option tells Docker that two containers 416 share the volume content. As a result, Docker labels the content with a shared 417 content label. Shared volume labels allow all containers to read/write content. 418 The `Z` option tells Docker to label the content with a private unshared label. 419 Only the current container can use a private volume. 420 421 ### Attach to STDIN/STDOUT/STDERR (-a) 422 423 The `-a` flag tells `docker run` to bind to the container's `STDIN`, `STDOUT` 424 or `STDERR`. This makes it possible to manipulate the output and input as 425 needed. 426 427 $ echo "test" | docker run -i -a stdin ubuntu cat - 428 429 This pipes data into a container and prints the container's ID by attaching 430 only to the container's `STDIN`. 431 432 $ docker run -a stderr ubuntu echo test 433 434 This isn't going to print anything unless there's an error because we've 435 only attached to the `STDERR` of the container. The container's logs 436 still store what's been written to `STDERR` and `STDOUT`. 437 438 $ cat somefile | docker run -i -a stdin mybuilder dobuild 439 440 This is how piping a file into a container could be done for a build. 441 The container's ID will be printed after the build is done and the build 442 logs could be retrieved using `docker logs`. This is 443 useful if you need to pipe a file or something else into a container and 444 retrieve the container's ID once the container has finished running. 445 446 ### Add host device to container (--device) 447 448 $ docker run --device=/dev/sdc:/dev/xvdc --device=/dev/sdd --device=/dev/zero:/dev/nulo -i -t ubuntu ls -l /dev/{xvdc,sdd,nulo} 449 brw-rw---- 1 root disk 8, 2 Feb 9 16:05 /dev/xvdc 450 brw-rw---- 1 root disk 8, 3 Feb 9 16:05 /dev/sdd 451 crw-rw-rw- 1 root root 1, 5 Feb 9 16:05 /dev/nulo 452 453 It is often necessary to directly expose devices to a container. The `--device` 454 option enables that. For example, a specific block storage device or loop 455 device or audio device can be added to an otherwise unprivileged container 456 (without the `--privileged` flag) and have the application directly access it. 457 458 By default, the container will be able to `read`, `write` and `mknod` these devices. 459 This can be overridden using a third `:rwm` set of options to each `--device` 460 flag: 461 462 463 $ docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk /dev/xvdc 464 465 Command (m for help): q 466 $ docker run --device=/dev/sda:/dev/xvdc:r --rm -it ubuntu fdisk /dev/xvdc 467 You will not be able to write the partition table. 468 469 Command (m for help): q 470 471 $ docker run --device=/dev/sda:/dev/xvdc:rw --rm -it ubuntu fdisk /dev/xvdc 472 473 Command (m for help): q 474 475 $ docker run --device=/dev/sda:/dev/xvdc:m --rm -it ubuntu fdisk /dev/xvdc 476 fdisk: unable to open /dev/xvdc: Operation not permitted 477 478 > **Note:** 479 > `--device` cannot be safely used with ephemeral devices. Block devices 480 > that may be removed should not be added to untrusted containers with 481 > `--device`. 482 483 ### Restart policies (--restart) 484 485 Use Docker's `--restart` to specify a container's *restart policy*. A restart 486 policy controls whether the Docker daemon restarts a container after exit. 487 Docker supports the following restart policies: 488 489 <table> 490 <thead> 491 <tr> 492 <th>Policy</th> 493 <th>Result</th> 494 </tr> 495 </thead> 496 <tbody> 497 <tr> 498 <td><strong>no</strong></td> 499 <td> 500 Do not automatically restart the container when it exits. This is the 501 default. 502 </td> 503 </tr> 504 <tr> 505 <td> 506 <span style="white-space: nowrap"> 507 <strong>on-failure</strong>[:max-retries] 508 </span> 509 </td> 510 <td> 511 Restart only if the container exits with a non-zero exit status. 512 Optionally, limit the number of restart retries the Docker 513 daemon attempts. 514 </td> 515 </tr> 516 <tr> 517 <td><strong>always</strong></td> 518 <td> 519 Always restart the container regardless of the exit status. 520 When you specify always, the Docker daemon will try to restart 521 the container indefinitely. The container will also always start 522 on daemon startup, regardless of the current state of the container. 523 </td> 524 </tr> 525 <tr> 526 <td><strong>unless-stopped</strong></td> 527 <td> 528 Always restart the container regardless of the exit status, but 529 do not start it on daemon startup if the container has been put 530 to a stopped state before. 531 </td> 532 </tr> 533 </tbody> 534 </table> 535 536 $ docker run --restart=always redis 537 538 This will run the `redis` container with a restart policy of **always** 539 so that if the container exits, Docker will restart it. 540 541 More detailed information on restart policies can be found in the 542 [Restart Policies (--restart)](../run.md#restart-policies-restart) 543 section of the Docker run reference page. 544 545 ### Add entries to container hosts file (--add-host) 546 547 You can add other hosts into a container's `/etc/hosts` file by using one or 548 more `--add-host` flags. This example adds a static address for a host named 549 `docker`: 550 551 $ docker run --add-host=docker:10.180.0.1 --rm -it debian 552 root@f38c87f2a42d:/# ping docker 553 PING docker (10.180.0.1): 48 data bytes 554 56 bytes from 10.180.0.1: icmp_seq=0 ttl=254 time=7.600 ms 555 56 bytes from 10.180.0.1: icmp_seq=1 ttl=254 time=30.705 ms 556 ^C--- docker ping statistics --- 557 2 packets transmitted, 2 packets received, 0% packet loss 558 round-trip min/avg/max/stddev = 7.600/19.152/30.705/11.553 ms 559 560 Sometimes you need to connect to the Docker host from within your 561 container. To enable this, pass the Docker host's IP address to 562 the container using the `--add-host` flag. To find the host's address, 563 use the `ip addr show` command. 564 565 The flags you pass to `ip addr show` depend on whether you are 566 using IPv4 or IPv6 networking in your containers. Use the following 567 flags for IPv4 address retrieval for a network device named `eth0`: 568 569 $ HOSTIP=`ip -4 addr show scope global dev eth0 | grep inet | awk '{print \$2}' | cut -d / -f 1` 570 $ docker run --add-host=docker:${HOSTIP} --rm -it debian 571 572 For IPv6 use the `-6` flag instead of the `-4` flag. For other network 573 devices, replace `eth0` with the correct device name (for example `docker0` 574 for the bridge device). 575 576 ### Set ulimits in container (--ulimit) 577 578 Since setting `ulimit` settings in a container requires extra privileges not 579 available in the default container, you can set these using the `--ulimit` flag. 580 `--ulimit` is specified with a soft and hard limit as such: 581 `<type>=<soft limit>[:<hard limit>]`, for example: 582 583 $ docker run --ulimit nofile=1024:1024 --rm debian sh -c "ulimit -n" 584 1024 585 586 > **Note:** 587 > If you do not provide a `hard limit`, the `soft limit` will be used 588 > for both values. If no `ulimits` are set, they will be inherited from 589 > the default `ulimits` set on the daemon. `as` option is disabled now. 590 > In other words, the following script is not supported: 591 > `$ docker run -it --ulimit as=1024 fedora /bin/bash` 592 593 The values are sent to the appropriate `syscall` as they are set. 594 Docker doesn't perform any byte conversion. Take this into account when setting the values. 595 596 #### For `nproc` usage 597 598 Be careful setting `nproc` with the `ulimit` flag as `nproc` is designed by Linux to set the 599 maximum number of processes available to a user, not to a container. For example, start four 600 containers with `daemon` user: 601 602 docker run -d -u daemon --ulimit nproc=3 busybox top 603 docker run -d -u daemon --ulimit nproc=3 busybox top 604 docker run -d -u daemon --ulimit nproc=3 busybox top 605 docker run -d -u daemon --ulimit nproc=3 busybox top 606 607 The 4th container fails and reports "[8] System error: resource temporarily unavailable" error. 608 This fails because the caller set `nproc=3` resulting in the first three containers using up 609 the three processes quota set for the `daemon` user. 610 611 ### Stop container with signal (--stop-signal) 612 613 The `--stop-signal` flag sets the system call signal that will be sent to the container to exit. 614 This signal can be a valid unsigned number that matches a position in the kernel's syscall table, for instance 9, 615 or a signal name in the format SIGNAME, for instance SIGKILL. 616 617 ### Specify isolation technology for container (--isolation) 618 619 This option is useful in situations where you are running Docker containers on 620 Microsoft Windows. The `--isolation <value>` option sets a container's isolation 621 technology. On Linux, the only supported is the `default` option which uses 622 Linux namespaces. These two commands are equivalent on Linux: 623 624 ``` 625 $ docker run -d busybox top 626 $ docker run -d --isolation default busybox top 627 ``` 628 629 On Microsoft Windows, can take any of these values: 630 631 632 | Value | Description | 633 |-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| 634 | `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. | 635 | `process` | Namespace isolation only. | 636 | `hyperv` | Hyper-V hypervisor partition-based isolation. | 637 638 On Windows, the default isolation for client is `hyperv`, and for server is 639 `process`. Therefore when running on Windows server without a `daemon` option 640 set, these two commands are equivalent: 641 ``` 642 $ docker run -d --isolation default busybox top 643 $ docker run -d --isolation process busybox top 644 ``` 645 646 If you have set the `--exec-opt isolation=hyperv` option on the Docker `daemon`, 647 if running on Windows server, any of these commands also result in `hyperv` isolation: 648 649 ``` 650 $ docker run -d --isolation default busybox top 651 $ docker run -d --isolation hyperv busybox top 652 ``` 653 654 ### Configure namespaced kernel parameters (sysctls) at runtime 655 656 The `--sysctl` sets namespaced kernel parameters (sysctls) in the 657 container. For example, to turn on IP forwarding in the containers 658 network namespace, run this command: 659 660 $ docker run --sysctl net.ipv4.ip_forward=1 someimage 661 662 663 > **Note**: Not all sysctls are namespaced. Docker does not support changing sysctls 664 > inside of a container that also modify the host system. As the kernel 665 > evolves we expect to see more sysctls become namespaced. 666 667 #### Currently supported sysctls 668 669 `IPC Namespace`: 670 671 kernel.msgmax, kernel.msgmnb, kernel.msgmni, kernel.sem, kernel.shmall, kernel.shmmax, kernel.shmmni, kernel.shm_rmid_forced 672 Sysctls beginning with fs.mqueue.* 673 674 If you use the `--ipc=host` option these sysctls will not be allowed. 675 676 `Network Namespace`: 677 Sysctls beginning with net.* 678 679 If you use the `--network=host` option using these sysctls will not be allowed.