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