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