github.com/fabiokung/docker@v0.11.2-0.20170222101415-4534dcd49497/docs/reference/run.md (about)

     1  ---
     2  title: "Docker run reference"
     3  description: "Configure containers at runtime"
     4  keywords: "docker, run, configure, runtime"
     5  ---
     6  
     7  <!-- This file is maintained within the docker/docker Github
     8       repository at https://github.com/docker/docker/. Make all
     9       pull requests against that repo. If you see this file in
    10       another repository, consider it read-only there, as it will
    11       periodically be overwritten by the definitive file. Pull
    12       requests which include edits to this file in other repositories
    13       will be rejected.
    14  -->
    15  
    16  # Docker run reference
    17  
    18  Docker runs processes in isolated containers. A container is a process
    19  which runs on a host. The host may be local or remote. When an operator
    20  executes `docker run`, the container process that runs is isolated in
    21  that it has its own file system, its own networking, and its own
    22  isolated process tree separate from the host.
    23  
    24  This page details how to use the `docker run` command to define the
    25  container's resources at runtime.
    26  
    27  ## General form
    28  
    29  The basic `docker run` command takes this form:
    30  
    31      $ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
    32  
    33  The `docker run` command must specify an [*IMAGE*](glossary.md#image)
    34  to derive the container from. An image developer can define image
    35  defaults related to:
    36  
    37   * detached or foreground running
    38   * container identification
    39   * network settings
    40   * runtime constraints on CPU and memory
    41  
    42  With the `docker run [OPTIONS]` an operator can add to or override the
    43  image defaults set by a developer. And, additionally, operators can
    44  override nearly all the defaults set by the Docker runtime itself. The
    45  operator's ability to override image and Docker runtime defaults is why
    46  [*run*](commandline/run.md) has more options than any
    47  other `docker` command.
    48  
    49  To learn how to interpret the types of `[OPTIONS]`, see [*Option
    50  types*](commandline/cli.md#option-types).
    51  
    52  > **Note**: Depending on your Docker system configuration, you may be
    53  > required to preface the `docker run` command with `sudo`. To avoid
    54  > having to use `sudo` with the `docker` command, your system
    55  > administrator can create a Unix group called `docker` and add users to
    56  > it. For more information about this configuration, refer to the Docker
    57  > installation documentation for your operating system.
    58  
    59  
    60  ## Operator exclusive options
    61  
    62  Only the operator (the person executing `docker run`) can set the
    63  following options.
    64  
    65   - [Detached vs foreground](#detached-vs-foreground)
    66       - [Detached (-d)](#detached--d)
    67       - [Foreground](#foreground)
    68   - [Container identification](#container-identification)
    69       - [Name (--name)](#name---name)
    70       - [PID equivalent](#pid-equivalent)
    71   - [IPC settings (--ipc)](#ipc-settings---ipc)
    72   - [Network settings](#network-settings)
    73   - [Restart policies (--restart)](#restart-policies---restart)
    74   - [Clean up (--rm)](#clean-up---rm)
    75   - [Runtime constraints on resources](#runtime-constraints-on-resources)
    76   - [Runtime privilege and Linux capabilities](#runtime-privilege-and-linux-capabilities)
    77  
    78  ## Detached vs foreground
    79  
    80  When starting a Docker container, you must first decide if you want to
    81  run the container in the background in a "detached" mode or in the
    82  default foreground mode:
    83  
    84      -d=false: Detached mode: Run container in the background, print new container id
    85  
    86  ### Detached (-d)
    87  
    88  To start a container in detached mode, you use `-d=true` or just `-d` option. By
    89  design, containers started in detached mode exit when the root process used to
    90  run the container exits. A container in detached mode cannot be automatically
    91  removed when it stops, this means you cannot use the `--rm` option with `-d` option.
    92  
    93  Do not pass a `service x start` command to a detached container. For example, this
    94  command attempts to start the `nginx` service.
    95  
    96      $ docker run -d -p 80:80 my_image service nginx start
    97  
    98  This succeeds in starting the `nginx` service inside the container. However, it
    99  fails the detached container paradigm in that, the root process (`service nginx
   100  start`) returns and the detached container stops as designed. As a result, the
   101  `nginx` service is started but could not be used. Instead, to start a process
   102  such as the `nginx` web server do the following:
   103  
   104      $ docker run -d -p 80:80 my_image nginx -g 'daemon off;'
   105  
   106  To do input/output with a detached container use network connections or shared
   107  volumes. These are required because the container is no longer listening to the
   108  command line where `docker run` was run.
   109  
   110  To reattach to a detached container, use `docker`
   111  [*attach*](commandline/attach.md) command.
   112  
   113  ### Foreground
   114  
   115  In foreground mode (the default when `-d` is not specified), `docker
   116  run` can start the process in the container and attach the console to
   117  the process's standard input, output, and standard error. It can even
   118  pretend to be a TTY (this is what most command line executables expect)
   119  and pass along signals. All of that is configurable:
   120  
   121      -a=[]           : Attach to `STDIN`, `STDOUT` and/or `STDERR`
   122      -t              : Allocate a pseudo-tty
   123      --sig-proxy=true: Proxy all received signals to the process (non-TTY mode only)
   124      -i              : Keep STDIN open even if not attached
   125  
   126  If you do not specify `-a` then Docker will [attach to both stdout and stderr
   127  ]( https://github.com/docker/docker/blob/4118e0c9eebda2412a09ae66e90c34b85fae3275/runconfig/opts/parse.go#L267).
   128  You can specify to which of the three standard streams (`STDIN`, `STDOUT`,
   129  `STDERR`) you'd like to connect instead, as in:
   130  
   131      $ docker run -a stdin -a stdout -i -t ubuntu /bin/bash
   132  
   133  For interactive processes (like a shell), you must use `-i -t` together in
   134  order to allocate a tty for the container process. `-i -t` is often written `-it`
   135  as you'll see in later examples.  Specifying `-t` is forbidden when the client
   136  standard output is redirected or piped, such as in:
   137  
   138      $ echo test | docker run -i busybox cat
   139  
   140  >**Note**: A process running as PID 1 inside a container is treated
   141  >specially by Linux: it ignores any signal with the default action.
   142  >So, the process will not terminate on `SIGINT` or `SIGTERM` unless it is
   143  >coded to do so.
   144  
   145  ## Container identification
   146  
   147  ### Name (--name)
   148  
   149  The operator can identify a container in three ways:
   150  
   151  | Identifier type       | Example value                                                      |
   152  | --------------------- | ------------------------------------------------------------------ |
   153  | UUID long identifier  | "f78375b1c487e03c9438c729345e54db9d20cfa2ac1fc3494b6eb60872e74778" |
   154  | UUID short identifier | "f78375b1c487"                                                     |
   155  | Name                  | "evil_ptolemy"                                                     |
   156  
   157  The UUID identifiers come from the Docker daemon. If you do not assign a
   158  container name with the `--name` option, then the daemon generates a random
   159  string name for you. Defining a `name` can be a handy way to add meaning to a
   160  container. If you specify a `name`, you can use it  when referencing the
   161  container within a Docker network. This works for both background and foreground
   162  Docker containers.
   163  
   164  > **Note**: Containers on the default bridge network must be linked to
   165  > communicate by name.
   166  
   167  ### PID equivalent
   168  
   169  Finally, to help with automation, you can have Docker write the
   170  container ID out to a file of your choosing. This is similar to how some
   171  programs might write out their process ID to a file (you've seen them as
   172  PID files):
   173  
   174      --cidfile="": Write the container ID to the file
   175  
   176  ### Image[:tag]
   177  
   178  While not strictly a means of identifying a container, you can specify a version of an
   179  image you'd like to run the container with by adding `image[:tag]` to the command. For
   180  example, `docker run ubuntu:14.04`.
   181  
   182  ### Image[@digest]
   183  
   184  Images using the v2 or later image format have a content-addressable identifier
   185  called a digest. As long as the input used to generate the image is unchanged,
   186  the digest value is predictable and referenceable.
   187  
   188  The following example runs a container from the `alpine` image with the
   189  `sha256:9cacb71397b640eca97488cf08582ae4e4068513101088e9f96c9814bfda95e0` digest:
   190  
   191      $ docker run alpine@sha256:9cacb71397b640eca97488cf08582ae4e4068513101088e9f96c9814bfda95e0 date
   192  
   193  ## PID settings (--pid)
   194  
   195      --pid=""  : Set the PID (Process) Namespace mode for the container,
   196                   'container:<name|id>': joins another container's PID namespace
   197                   'host': use the host's PID namespace inside the container
   198  
   199  By default, all containers have the PID namespace enabled.
   200  
   201  PID namespace provides separation of processes. The PID Namespace removes the
   202  view of the system processes, and allows process ids to be reused including
   203  pid 1.
   204  
   205  In certain cases you want your container to share the host's process namespace,
   206  basically allowing processes within the container to see all of the processes
   207  on the system.  For example, you could build a container with debugging tools
   208  like `strace` or `gdb`, but want to use these tools when debugging processes
   209  within the container.
   210  
   211  ### Example: run htop inside a container
   212  
   213  Create this Dockerfile:
   214  
   215  ```
   216  FROM alpine:latest
   217  RUN apk add --update htop && rm -rf /var/cache/apk/*
   218  CMD ["htop"]
   219  ```
   220  
   221  Build the Dockerfile and tag the image as `myhtop`:
   222  
   223  ```bash
   224  $ docker build -t myhtop .
   225  ```
   226  
   227  Use the following command to run `htop` inside a container:
   228  
   229  ```
   230  $ docker run -it --rm --pid=host myhtop
   231  ```
   232  
   233  Joining another container's pid namespace can be used for debugging that container.
   234  
   235  ### Example
   236  
   237  Start a container running a redis server:
   238  
   239  ```bash
   240  $ docker run --name my-redis -d redis
   241  ```
   242  
   243  Debug the redis container by running another container that has strace in it:
   244  
   245  ```bash
   246  $ docker run -it --pid=container:my-redis my_strace_docker_image bash
   247  $ strace -p 1
   248  ```
   249  
   250  ## UTS settings (--uts)
   251  
   252      --uts=""  : Set the UTS namespace mode for the container,
   253             'host': use the host's UTS namespace inside the container
   254  
   255  The UTS namespace is for setting the hostname and the domain that is visible
   256  to running processes in that namespace.  By default, all containers, including
   257  those with `--network=host`, have their own UTS namespace.  The `host` setting will
   258  result in the container using the same UTS namespace as the host.  Note that
   259  `--hostname` is invalid in `host` UTS mode.
   260  
   261  You may wish to share the UTS namespace with the host if you would like the
   262  hostname of the container to change as the hostname of the host changes.  A
   263  more advanced use case would be changing the host's hostname from a container.
   264  
   265  ## IPC settings (--ipc)
   266  
   267      --ipc=""  : Set the IPC mode for the container,
   268                   'container:<name|id>': reuses another container's IPC namespace
   269                   'host': use the host's IPC namespace inside the container
   270  
   271  By default, all containers have the IPC namespace enabled.
   272  
   273  IPC (POSIX/SysV IPC) namespace provides separation of named shared memory
   274  segments, semaphores and message queues.
   275  
   276  Shared memory segments are used to accelerate inter-process communication at
   277  memory speed, rather than through pipes or through the network stack. Shared
   278  memory is commonly used by databases and custom-built (typically C/OpenMPI,
   279  C++/using boost libraries) high performance applications for scientific
   280  computing and financial services industries. If these types of applications
   281  are broken into multiple containers, you might need to share the IPC mechanisms
   282  of the containers.
   283  
   284  ## Network settings
   285  
   286      --dns=[]           : Set custom dns servers for the container
   287      --network="bridge" : Connect a container to a network
   288                            'bridge': create a network stack on the default Docker bridge
   289                            'none': no networking
   290                            'container:<name|id>': reuse another container's network stack
   291                            'host': use the Docker host network stack
   292                            '<network-name>|<network-id>': connect to a user-defined network
   293      --network-alias=[] : Add network-scoped alias for the container
   294      --add-host=""      : Add a line to /etc/hosts (host:IP)
   295      --mac-address=""   : Sets the container's Ethernet device's MAC address
   296      --ip=""            : Sets the container's Ethernet device's IPv4 address
   297      --ip6=""           : Sets the container's Ethernet device's IPv6 address
   298      --link-local-ip=[] : Sets one or more container's Ethernet device's link local IPv4/IPv6 addresses
   299  
   300  By default, all containers have networking enabled and they can make any
   301  outgoing connections. The operator can completely disable networking
   302  with `docker run --network none` which disables all incoming and outgoing
   303  networking. In cases like this, you would perform I/O through files or
   304  `STDIN` and `STDOUT` only.
   305  
   306  Publishing ports and linking to other containers only works with the default (bridge). The linking feature is a legacy feature. You should always prefer using Docker network drivers over linking.
   307  
   308  Your container will use the same DNS servers as the host by default, but
   309  you can override this with `--dns`.
   310  
   311  By default, the MAC address is generated using the IP address allocated to the
   312  container. You can set the container's MAC address explicitly by providing a
   313  MAC address via the `--mac-address` parameter (format:`12:34:56:78:9a:bc`).Be
   314  aware that Docker does not check if manually specified MAC addresses are unique.
   315  
   316  Supported networks :
   317  
   318  <table>
   319    <thead>
   320      <tr>
   321        <th class="no-wrap">Network</th>
   322        <th>Description</th>
   323      </tr>
   324    </thead>
   325    <tbody>
   326      <tr>
   327        <td class="no-wrap"><strong>none</strong></td>
   328        <td>
   329          No networking in the container.
   330        </td>
   331      </tr>
   332      <tr>
   333        <td class="no-wrap"><strong>bridge</strong> (default)</td>
   334        <td>
   335          Connect the container to the bridge via veth interfaces.
   336        </td>
   337      </tr>
   338      <tr>
   339        <td class="no-wrap"><strong>host</strong></td>
   340        <td>
   341          Use the host's network stack inside the container.
   342        </td>
   343      </tr>
   344      <tr>
   345        <td class="no-wrap"><strong>container</strong>:&lt;name|id&gt;</td>
   346        <td>
   347          Use the network stack of another container, specified via
   348          its <i>name</i> or <i>id</i>.
   349        </td>
   350      </tr>
   351      <tr>
   352        <td class="no-wrap"><strong>NETWORK</strong></td>
   353        <td>
   354          Connects the container to a user created network (using <code>docker network create</code> command)
   355        </td>
   356      </tr>
   357    </tbody>
   358  </table>
   359  
   360  #### Network: none
   361  
   362  With the network is `none` a container will not have
   363  access to any external routes.  The container will still have a
   364  `loopback` interface enabled in the container but it does not have any
   365  routes to external traffic.
   366  
   367  #### Network: bridge
   368  
   369  With the network set to `bridge` a container will use docker's
   370  default networking setup.  A bridge is setup on the host, commonly named
   371  `docker0`, and a pair of `veth` interfaces will be created for the
   372  container.  One side of the `veth` pair will remain on the host attached
   373  to the bridge while the other side of the pair will be placed inside the
   374  container's namespaces in addition to the `loopback` interface.  An IP
   375  address will be allocated for containers on the bridge's network and
   376  traffic will be routed though this bridge to the container.
   377  
   378  Containers can communicate via their IP addresses by default. To communicate by
   379  name, they must be linked.
   380  
   381  #### Network: host
   382  
   383  With the network set to `host` a container will share the host's
   384  network stack and all interfaces from the host will be available to the
   385  container.  The container's hostname will match the hostname on the host
   386  system. Note that `--mac-address` is invalid in `host` netmode. Even in `host`
   387  network mode a container has its own UTS namespace by default. As such
   388  `--hostname` is allowed in `host` network mode and will only change the
   389  hostname inside the container.
   390  Similar to `--hostname`, the `--add-host`, `--dns`, `--dns-search`, and
   391  `--dns-option` options can be used in `host` network mode. These options update
   392  `/etc/hosts` or `/etc/resolv.conf` inside the container. No change are made to
   393  `/etc/hosts` and `/etc/resolv.conf` on the host.
   394  
   395  Compared to the default `bridge` mode, the `host` mode gives *significantly*
   396  better networking performance since it uses the host's native networking stack
   397  whereas the bridge has to go through one level of virtualization through the
   398  docker daemon. It is recommended to run containers in this mode when their
   399  networking performance is critical, for example, a production Load Balancer
   400  or a High Performance Web Server.
   401  
   402  > **Note**: `--network="host"` gives the container full access to local system
   403  > services such as D-bus and is therefore considered insecure.
   404  
   405  #### Network: container
   406  
   407  With the network set to `container` a container will share the
   408  network stack of another container.  The other container's name must be
   409  provided in the format of `--network container:<name|id>`. Note that `--add-host`
   410  `--hostname` `--dns` `--dns-search` `--dns-option` and `--mac-address` are
   411  invalid in `container` netmode, and `--publish` `--publish-all` `--expose` are
   412  also invalid in `container` netmode.
   413  
   414  Example running a Redis container with Redis binding to `localhost` then
   415  running the `redis-cli` command and connecting to the Redis server over the
   416  `localhost` interface.
   417  
   418      $ docker run -d --name redis example/redis --bind 127.0.0.1
   419      $ # use the redis container's network stack to access localhost
   420      $ docker run --rm -it --network container:redis example/redis-cli -h 127.0.0.1
   421  
   422  #### User-defined network
   423  
   424  You can create a network using a Docker network driver or an external network
   425  driver plugin. You can connect multiple containers to the same network. Once
   426  connected to a user-defined network, the containers can communicate easily using
   427  only another container's IP address or name.
   428  
   429  For `overlay` networks or custom plugins that support multi-host connectivity,
   430  containers connected to the same multi-host network but launched from different
   431  Engines can also communicate in this way.
   432  
   433  The following example creates a network using the built-in `bridge` network
   434  driver and running a container in the created network
   435  
   436  ```
   437  $ docker network create -d bridge my-net
   438  $ docker run --network=my-net -itd --name=container3 busybox
   439  ```
   440  
   441  ### Managing /etc/hosts
   442  
   443  Your container will have lines in `/etc/hosts` which define the hostname of the
   444  container itself as well as `localhost` and a few other common things. The
   445  `--add-host` flag can be used to add additional lines to `/etc/hosts`.
   446  
   447      $ docker run -it --add-host db-static:86.75.30.9 ubuntu cat /etc/hosts
   448      172.17.0.22     09d03f76bf2c
   449      fe00::0         ip6-localnet
   450      ff00::0         ip6-mcastprefix
   451      ff02::1         ip6-allnodes
   452      ff02::2         ip6-allrouters
   453      127.0.0.1       localhost
   454      ::1	            localhost ip6-localhost ip6-loopback
   455      86.75.30.9      db-static
   456  
   457  If a container is connected to the default bridge network and `linked`
   458  with other containers, then the container's `/etc/hosts` file is updated
   459  with the linked container's name.
   460  
   461  If the container is connected to user-defined network, the container's
   462  `/etc/hosts` file is updated with names of all other containers in that
   463  user-defined network.
   464  
   465  > **Note** Since Docker may live update the container’s `/etc/hosts` file, there
   466  may be situations when processes inside the container can end up reading an
   467  empty or incomplete `/etc/hosts` file. In most cases, retrying the read again
   468  should fix the problem.
   469  
   470  ## Restart policies (--restart)
   471  
   472  Using the `--restart` flag on Docker run you can specify a restart policy for
   473  how a container should or should not be restarted on exit.
   474  
   475  When a restart policy is active on a container, it will be shown as either `Up`
   476  or `Restarting` in [`docker ps`](commandline/ps.md). It can also be
   477  useful to use [`docker events`](commandline/events.md) to see the
   478  restart policy in effect.
   479  
   480  Docker supports the following restart policies:
   481  
   482  <table>
   483    <thead>
   484      <tr>
   485        <th>Policy</th>
   486        <th>Result</th>
   487      </tr>
   488    </thead>
   489    <tbody>
   490      <tr>
   491        <td><strong>no</strong></td>
   492        <td>
   493          Do not automatically restart the container when it exits. This is the
   494          default.
   495        </td>
   496      </tr>
   497      <tr>
   498        <td>
   499          <span style="white-space: nowrap">
   500            <strong>on-failure</strong>[:max-retries]
   501          </span>
   502        </td>
   503        <td>
   504          Restart only if the container exits with a non-zero exit status.
   505          Optionally, limit the number of restart retries the Docker
   506          daemon attempts.
   507        </td>
   508      </tr>
   509      <tr>
   510        <td><strong>always</strong></td>
   511        <td>
   512          Always restart the container regardless of the exit status.
   513          When you specify always, the Docker daemon will try to restart
   514          the container indefinitely. The container will also always start
   515          on daemon startup, regardless of the current state of the container.
   516        </td>
   517      </tr>
   518      <tr>
   519        <td><strong>unless-stopped</strong></td>
   520        <td>
   521          Always restart the container regardless of the exit status, but
   522          do not start it on daemon startup if the container has been put
   523          to a stopped state before.
   524        </td>
   525      </tr>
   526    </tbody>
   527  </table>
   528  
   529  An ever increasing delay (double the previous delay, starting at 100
   530  milliseconds) is added before each restart to prevent flooding the server.
   531  This means the daemon will wait for 100 ms, then 200 ms, 400, 800, 1600,
   532  and so on until either the `on-failure` limit is hit, or when you `docker stop`
   533  or `docker rm -f` the container.
   534  
   535  If a container is successfully restarted (the container is started and runs
   536  for at least 10 seconds), the delay is reset to its default value of 100 ms.
   537  
   538  You can specify the maximum amount of times Docker will try to restart the
   539  container when using the **on-failure** policy.  The default is that Docker
   540  will try forever to restart the container. The number of (attempted) restarts
   541  for a container can be obtained via [`docker inspect`](commandline/inspect.md). For example, to get the number of restarts
   542  for container "my-container";
   543  
   544      {% raw %}
   545      $ docker inspect -f "{{ .RestartCount }}" my-container
   546      # 2
   547      {% endraw %}
   548  
   549  Or, to get the last time the container was (re)started;
   550  
   551      {% raw %}
   552      $ docker inspect -f "{{ .State.StartedAt }}" my-container
   553      # 2015-03-04T23:47:07.691840179Z
   554      {% endraw %}
   555  
   556  
   557  Combining `--restart` (restart policy) with the `--rm` (clean up) flag results
   558  in an error. On container restart, attached clients are disconnected. See the
   559  examples on using the [`--rm` (clean up)](#clean-up-rm) flag later in this page.
   560  
   561  ### Examples
   562  
   563      $ docker run --restart=always redis
   564  
   565  This will run the `redis` container with a restart policy of **always**
   566  so that if the container exits, Docker will restart it.
   567  
   568      $ docker run --restart=on-failure:10 redis
   569  
   570  This will run the `redis` container with a restart policy of **on-failure**
   571  and a maximum restart count of 10.  If the `redis` container exits with a
   572  non-zero exit status more than 10 times in a row Docker will abort trying to
   573  restart the container. Providing a maximum restart limit is only valid for the
   574  **on-failure** policy.
   575  
   576  ## Exit Status
   577  
   578  The exit code from `docker run` gives information about why the container
   579  failed to run or why it exited.  When `docker run` exits with a non-zero code,
   580  the exit codes follow the `chroot` standard, see below:
   581  
   582  **_125_** if the error is with Docker daemon **_itself_**
   583  
   584      $ docker run --foo busybox; echo $?
   585      # flag provided but not defined: --foo
   586        See 'docker run --help'.
   587        125
   588  
   589  **_126_** if the **_contained command_** cannot be invoked
   590  
   591      $ docker run busybox /etc; echo $?
   592      # docker: Error response from daemon: Container command '/etc' could not be invoked.
   593        126
   594  
   595  **_127_** if the **_contained command_** cannot be found
   596  
   597      $ docker run busybox foo; echo $?
   598      # docker: Error response from daemon: Container command 'foo' not found or does not exist.
   599        127
   600  
   601  **_Exit code_** of **_contained command_** otherwise
   602  
   603      $ docker run busybox /bin/sh -c 'exit 3'; echo $?
   604      # 3
   605  
   606  ## Clean up (--rm)
   607  
   608  By default a container's file system persists even after the container
   609  exits. This makes debugging a lot easier (since you can inspect the
   610  final state) and you retain all your data by default. But if you are
   611  running short-term **foreground** processes, these container file
   612  systems can really pile up. If instead you'd like Docker to
   613  **automatically clean up the container and remove the file system when
   614  the container exits**, you can add the `--rm` flag:
   615  
   616      --rm=false: Automatically remove the container when it exits (incompatible with -d)
   617  
   618  > **Note**: When you set the `--rm` flag, Docker also removes the volumes
   619  associated with the container when the container is removed. This is similar
   620  to running `docker rm -v my-container`. Only volumes that are specified without a
   621  name are removed. For example, with
   622  `docker run --rm -v /foo -v awesome:/bar busybox top`, the volume for `/foo` will be removed,
   623  but the volume for `/bar` will not. Volumes inherited via `--volumes-from` will be removed
   624  with the same logic -- if the original volume was specified with a name it will **not** be removed.
   625  
   626  ## Security configuration
   627      --security-opt="label=user:USER"     : Set the label user for the container
   628      --security-opt="label=role:ROLE"     : Set the label role for the container
   629      --security-opt="label=type:TYPE"     : Set the label type for the container
   630      --security-opt="label=level:LEVEL"   : Set the label level for the container
   631      --security-opt="label=disable"       : Turn off label confinement for the container
   632      --security-opt="apparmor=PROFILE"    : Set the apparmor profile to be applied to the container
   633      --security-opt="no-new-privileges:true|false"   : Disable/enable container processes from gaining new privileges
   634      --security-opt="seccomp=unconfined"  : Turn off seccomp confinement for the container
   635      --security-opt="seccomp=profile.json": White listed syscalls seccomp Json file to be used as a seccomp filter
   636  
   637  
   638  You can override the default labeling scheme for each container by specifying
   639  the `--security-opt` flag. Specifying the level in the following command
   640  allows you to share the same content between containers.
   641  
   642      $ docker run --security-opt label=level:s0:c100,c200 -it fedora bash
   643  
   644  > **Note**: Automatic translation of MLS labels is not currently supported.
   645  
   646  To disable the security labeling for this container versus running with the
   647  `--privileged` flag, use the following command:
   648  
   649      $ docker run --security-opt label=disable -it fedora bash
   650  
   651  If you want a tighter security policy on the processes within a container,
   652  you can specify an alternate type for the container. You could run a container
   653  that is only allowed to listen on Apache ports by executing the following
   654  command:
   655  
   656      $ docker run --security-opt label=type:svirt_apache_t -it centos bash
   657  
   658  > **Note**: You would have to write policy defining a `svirt_apache_t` type.
   659  
   660  If you want to prevent your container processes from gaining additional
   661  privileges, you can execute the following command:
   662  
   663      $ docker run --security-opt no-new-privileges -it centos bash
   664  
   665  This means that commands that raise privileges such as `su` or `sudo` will no longer work.
   666  It also causes any seccomp filters to be applied later, after privileges have been dropped
   667  which may mean you can have a more restrictive set of filters.
   668  For more details, see the [kernel documentation](https://www.kernel.org/doc/Documentation/prctl/no_new_privs.txt).
   669  
   670  ## Specify an init process
   671  
   672  You can use the `--init` flag to indicate that an init process should be used as
   673  the PID 1 in the container. Specifying an init process ensures the usual
   674  responsibilities of an init system, such as reaping zombie processes, are
   675  performed inside the created container.
   676  
   677  The default init process used is the first `docker-init` executable found in the
   678  system path of the Docker daemon process. This `docker-init` binary, included in
   679  the default installation, is backed by [tini](https://github.com/krallin/tini).
   680  
   681  ## Specify custom cgroups
   682  
   683  Using the `--cgroup-parent` flag, you can pass a specific cgroup to run a
   684  container in. This allows you to create and manage cgroups on their own. You can
   685  define custom resources for those cgroups and put containers under a common
   686  parent group.
   687  
   688  ## Runtime constraints on resources
   689  
   690  The operator can also adjust the performance parameters of the
   691  container:
   692  
   693  | Option                     |  Description                                                                                                                                    |
   694  | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
   695  | `-m`, `--memory=""`        | Memory limit (format: `<number>[<unit>]`). Number is a positive integer. Unit can be one of `b`, `k`, `m`, or `g`. Minimum is 4M.               |
   696  | `--memory-swap=""`         | Total memory limit (memory + swap, format: `<number>[<unit>]`). Number is a positive integer. Unit can be one of `b`, `k`, `m`, or `g`.         |
   697  | `--memory-reservation=""`  | Memory soft limit (format: `<number>[<unit>]`). Number is a positive integer. Unit can be one of `b`, `k`, `m`, or `g`.                         |
   698  | `--kernel-memory=""`       | Kernel memory limit (format: `<number>[<unit>]`). Number is a positive integer. Unit can be one of `b`, `k`, `m`, or `g`. Minimum is 4M.        |
   699  | `-c`, `--cpu-shares=0`     | CPU shares (relative weight)                                                                                                                    |
   700  | `--cpus=0.000`             | Number of CPUs. Number is a fractional number. 0.000 means no limit.                                                                            |
   701  | `--cpu-period=0`           | Limit the CPU CFS (Completely Fair Scheduler) period                                                                                            |
   702  | `--cpuset-cpus=""`         | CPUs in which to allow execution (0-3, 0,1)                                                                                                     |
   703  | `--cpuset-mems=""`         | Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.                                                     |
   704  | `--cpu-quota=0`            | Limit the CPU CFS (Completely Fair Scheduler) quota                                                                                             |
   705  | `--cpu-rt-period=0`        | Limit the CPU real-time period. In microseconds. Requires parent cgroups be set and cannot be higher than parent. Also check rtprio ulimits.    |
   706  | `--cpu-rt-runtime=0`       | Limit the CPU real-time runtime. In microseconds. Requires parent cgroups be set and cannot be higher than parent. Also check rtprio ulimits.   |
   707  | `--blkio-weight=0`         | Block IO weight (relative weight) accepts a weight value between 10 and 1000.                                                                   |
   708  | `--blkio-weight-device=""` | Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`)                                                                          |
   709  | `--device-read-bps=""`     | Limit read rate from a device (format: `<device-path>:<number>[<unit>]`). Number is a positive integer. Unit can be one of `kb`, `mb`, or `gb`. |
   710  | `--device-write-bps=""`    | Limit write rate to a device (format: `<device-path>:<number>[<unit>]`). Number is a positive integer. Unit can be one of `kb`, `mb`, or `gb`.  |
   711  | `--device-read-iops="" `   | Limit read rate (IO per second) from a device (format: `<device-path>:<number>`). Number is a positive integer.                                 |
   712  | `--device-write-iops="" `  | Limit write rate (IO per second) to a device (format: `<device-path>:<number>`). Number is a positive integer.                                  |
   713  | `--oom-kill-disable=false` | Whether to disable OOM Killer for the container or not.                                                                                         |
   714  | `--oom-score-adj=0`        | Tune container's OOM preferences (-1000 to 1000)                                                                                                |
   715  | `--memory-swappiness=""`   | Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100.                                                            |
   716  | `--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`. |
   717  
   718  ### User memory constraints
   719  
   720  We have four ways to set user memory usage:
   721  
   722  <table>
   723    <thead>
   724      <tr>
   725        <th>Option</th>
   726        <th>Result</th>
   727      </tr>
   728    </thead>
   729    <tbody>
   730      <tr>
   731        <td class="no-wrap">
   732            <strong>memory=inf, memory-swap=inf</strong> (default)
   733        </td>
   734        <td>
   735          There is no memory limit for the container. The container can use
   736          as much memory as needed.
   737        </td>
   738      </tr>
   739      <tr>
   740        <td class="no-wrap"><strong>memory=L&lt;inf, memory-swap=inf</strong></td>
   741        <td>
   742          (specify memory and set memory-swap as <code>-1</code>) The container is
   743          not allowed to use more than L bytes of memory, but can use as much swap
   744          as is needed (if the host supports swap memory).
   745        </td>
   746      </tr>
   747      <tr>
   748        <td class="no-wrap"><strong>memory=L&lt;inf, memory-swap=2*L</strong></td>
   749        <td>
   750          (specify memory without memory-swap) The container is not allowed to
   751          use more than L bytes of memory, swap <i>plus</i> memory usage is double
   752          of that.
   753        </td>
   754      </tr>
   755      <tr>
   756        <td class="no-wrap">
   757            <strong>memory=L&lt;inf, memory-swap=S&lt;inf, L&lt;=S</strong>
   758        </td>
   759        <td>
   760          (specify both memory and memory-swap) The container is not allowed to
   761          use more than L bytes of memory, swap <i>plus</i> memory usage is limited
   762          by S.
   763        </td>
   764      </tr>
   765    </tbody>
   766  </table>
   767  
   768  Examples:
   769  
   770      $ docker run -it ubuntu:14.04 /bin/bash
   771  
   772  We set nothing about memory, this means the processes in the container can use
   773  as much memory and swap memory as they need.
   774  
   775      $ docker run -it -m 300M --memory-swap -1 ubuntu:14.04 /bin/bash
   776  
   777  We set memory limit and disabled swap memory limit, this means the processes in
   778  the container can use 300M memory and as much swap memory as they need (if the
   779  host supports swap memory).
   780  
   781      $ docker run -it -m 300M ubuntu:14.04 /bin/bash
   782  
   783  We set memory limit only, this means the processes in the container can use
   784  300M memory and 300M swap memory, by default, the total virtual memory size
   785  (--memory-swap) will be set as double of memory, in this case, memory + swap
   786  would be 2*300M, so processes can use 300M swap memory as well.
   787  
   788      $ docker run -it -m 300M --memory-swap 1G ubuntu:14.04 /bin/bash
   789  
   790  We set both memory and swap memory, so the processes in the container can use
   791  300M memory and 700M swap memory.
   792  
   793  Memory reservation is a kind of memory soft limit that allows for greater
   794  sharing of memory. Under normal circumstances, containers can use as much of
   795  the memory as needed and are constrained only by the hard limits set with the
   796  `-m`/`--memory` option. When memory reservation is set, Docker detects memory
   797  contention or low memory and forces containers to restrict their consumption to
   798  a reservation limit.
   799  
   800  Always set the memory reservation value below the hard limit, otherwise the hard
   801  limit takes precedence. A reservation of 0 is the same as setting no
   802  reservation. By default (without reservation set), memory reservation is the
   803  same as the hard memory limit.
   804  
   805  Memory reservation is a soft-limit feature and does not guarantee the limit
   806  won't be exceeded. Instead, the feature attempts to ensure that, when memory is
   807  heavily contended for, memory is allocated based on the reservation hints/setup.
   808  
   809  The following example limits the memory (`-m`) to 500M and sets the memory
   810  reservation to 200M.
   811  
   812  ```bash
   813  $ docker run -it -m 500M --memory-reservation 200M ubuntu:14.04 /bin/bash
   814  ```
   815  
   816  Under this configuration, when the container consumes memory more than 200M and
   817  less than 500M, the next system memory reclaim attempts to shrink container
   818  memory below 200M.
   819  
   820  The following example set memory reservation to 1G without a hard memory limit.
   821  
   822  ```bash
   823  $ docker run -it --memory-reservation 1G ubuntu:14.04 /bin/bash
   824  ```
   825  
   826  The container can use as much memory as it needs. The memory reservation setting
   827  ensures the container doesn't consume too much memory for long time, because
   828  every memory reclaim shrinks the container's consumption to the reservation.
   829  
   830  By default, kernel kills processes in a container if an out-of-memory (OOM)
   831  error occurs. To change this behaviour, use the `--oom-kill-disable` option.
   832  Only disable the OOM killer on containers where you have also set the
   833  `-m/--memory` option. If the `-m` flag is not set, this can result in the host
   834  running out of memory and require killing the host's system processes to free
   835  memory.
   836  
   837  The following example limits the memory to 100M and disables the OOM killer for
   838  this container:
   839  
   840      $ docker run -it -m 100M --oom-kill-disable ubuntu:14.04 /bin/bash
   841  
   842  The following example, illustrates a dangerous way to use the flag:
   843  
   844      $ docker run -it --oom-kill-disable ubuntu:14.04 /bin/bash
   845  
   846  The container has unlimited memory which can cause the host to run out memory
   847  and require killing system processes to free memory. The `--oom-score-adj`
   848  parameter can be changed to select the priority of which containers will
   849  be killed when the system is out of memory, with negative scores making them
   850  less likely to be killed, and positive scores more likely.
   851  
   852  ### Kernel memory constraints
   853  
   854  Kernel memory is fundamentally different than user memory as kernel memory can't
   855  be swapped out. The inability to swap makes it possible for the container to
   856  block system services by consuming too much kernel memory. Kernel memory includes:
   857  
   858   - stack pages
   859   - slab pages
   860   - sockets memory pressure
   861   - tcp memory pressure
   862  
   863  You can setup kernel memory limit to constrain these kinds of memory. For example,
   864  every process consumes some stack pages. By limiting kernel memory, you can
   865  prevent new processes from being created when the kernel memory usage is too high.
   866  
   867  Kernel memory is never completely independent of user memory. Instead, you limit
   868  kernel memory in the context of the user memory limit. Assume "U" is the user memory
   869  limit and "K" the kernel limit. There are three possible ways to set limits:
   870  
   871  <table>
   872    <thead>
   873      <tr>
   874        <th>Option</th>
   875        <th>Result</th>
   876      </tr>
   877    </thead>
   878    <tbody>
   879      <tr>
   880        <td class="no-wrap"><strong>U != 0, K = inf</strong> (default)</td>
   881        <td>
   882          This is the standard memory limitation mechanism already present before using
   883          kernel memory. Kernel memory is completely ignored.
   884        </td>
   885      </tr>
   886      <tr>
   887        <td class="no-wrap"><strong>U != 0, K &lt; U</strong></td>
   888        <td>
   889          Kernel memory is a subset of the user memory. This setup is useful in
   890          deployments where the total amount of memory per-cgroup is overcommitted.
   891          Overcommitting kernel memory limits is definitely not recommended, since the
   892          box can still run out of non-reclaimable memory.
   893          In this case, you can configure K so that the sum of all groups is
   894          never greater than the total memory. Then, freely set U at the expense of
   895          the system's service quality.
   896        </td>
   897      </tr>
   898      <tr>
   899        <td class="no-wrap"><strong>U != 0, K &gt; U</strong></td>
   900        <td>
   901          Since kernel memory charges are also fed to the user counter and reclamation
   902          is triggered for the container for both kinds of memory. This configuration
   903          gives the admin a unified view of memory. It is also useful for people
   904          who just want to track kernel memory usage.
   905        </td>
   906      </tr>
   907    </tbody>
   908  </table>
   909  
   910  Examples:
   911  
   912      $ docker run -it -m 500M --kernel-memory 50M ubuntu:14.04 /bin/bash
   913  
   914  We set memory and kernel memory, so the processes in the container can use
   915  500M memory in total, in this 500M memory, it can be 50M kernel memory tops.
   916  
   917      $ docker run -it --kernel-memory 50M ubuntu:14.04 /bin/bash
   918  
   919  We set kernel memory without **-m**, so the processes in the container can
   920  use as much memory as they want, but they can only use 50M kernel memory.
   921  
   922  ### Swappiness constraint
   923  
   924  By default, a container's kernel can swap out a percentage of anonymous pages.
   925  To set this percentage for a container, specify a `--memory-swappiness` value
   926  between 0 and 100. A value of 0 turns off anonymous page swapping. A value of
   927  100 sets all anonymous pages as swappable. By default, if you are not using
   928  `--memory-swappiness`, memory swappiness value will be inherited from the parent.
   929  
   930  For example, you can set:
   931  
   932      $ docker run -it --memory-swappiness=0 ubuntu:14.04 /bin/bash
   933  
   934  Setting the `--memory-swappiness` option is helpful when you want to retain the
   935  container's working set and to avoid swapping performance penalties.
   936  
   937  ### CPU share constraint
   938  
   939  By default, all containers get the same proportion of CPU cycles. This proportion
   940  can be modified by changing the container's CPU share weighting relative
   941  to the weighting of all other running containers.
   942  
   943  To modify the proportion from the default of 1024, use the `-c` or `--cpu-shares`
   944  flag to set the weighting to 2 or higher. If 0 is set, the system will ignore the
   945  value and use the default of 1024.
   946  
   947  The proportion will only apply when CPU-intensive processes are running.
   948  When tasks in one container are idle, other containers can use the
   949  left-over CPU time. The actual amount of CPU time will vary depending on
   950  the number of containers running on the system.
   951  
   952  For example, consider three containers, one has a cpu-share of 1024 and
   953  two others have a cpu-share setting of 512. When processes in all three
   954  containers attempt to use 100% of CPU, the first container would receive
   955  50% of the total CPU time. If you add a fourth container with a cpu-share
   956  of 1024, the first container only gets 33% of the CPU. The remaining containers
   957  receive 16.5%, 16.5% and 33% of the CPU.
   958  
   959  On a multi-core system, the shares of CPU time are distributed over all CPU
   960  cores. Even if a container is limited to less than 100% of CPU time, it can
   961  use 100% of each individual CPU core.
   962  
   963  For example, consider a system with more than three cores. If you start one
   964  container `{C0}` with `-c=512` running one process, and another container
   965  `{C1}` with `-c=1024` running two processes, this can result in the following
   966  division of CPU shares:
   967  
   968      PID    container	CPU	CPU share
   969      100    {C0}		0	100% of CPU0
   970      101    {C1}		1	100% of CPU1
   971      102    {C1}		2	100% of CPU2
   972  
   973  ### CPU period constraint
   974  
   975  The default CPU CFS (Completely Fair Scheduler) period is 100ms. We can use
   976  `--cpu-period` to set the period of CPUs to limit the container's CPU usage.
   977  And usually `--cpu-period` should work with `--cpu-quota`.
   978  
   979  Examples:
   980  
   981      $ docker run -it --cpu-period=50000 --cpu-quota=25000 ubuntu:14.04 /bin/bash
   982  
   983  If there is 1 CPU, this means the container can get 50% CPU worth of run-time every 50ms.
   984  
   985  In addition to use `--cpu-period` and `--cpu-quota` for setting CPU period constraints,
   986  it is possible to specify `--cpus` with a float number to achieve the same purpose.
   987  For example, if there is 1 CPU, then `--cpus=0.5` will achieve the same result as
   988  setting `--cpu-period=50000` and `--cpu-quota=25000` (50% CPU).
   989  
   990  The default value for `--cpus` is `0.000`, which means there is no limit.
   991  
   992  For more information, see the [CFS documentation on bandwidth limiting](https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt).
   993  
   994  ### Cpuset constraint
   995  
   996  We can set cpus in which to allow execution for containers.
   997  
   998  Examples:
   999  
  1000      $ docker run -it --cpuset-cpus="1,3" ubuntu:14.04 /bin/bash
  1001  
  1002  This means processes in container can be executed on cpu 1 and cpu 3.
  1003  
  1004      $ docker run -it --cpuset-cpus="0-2" ubuntu:14.04 /bin/bash
  1005  
  1006  This means processes in container can be executed on cpu 0, cpu 1 and cpu 2.
  1007  
  1008  We can set mems in which to allow execution for containers. Only effective
  1009  on NUMA systems.
  1010  
  1011  Examples:
  1012  
  1013      $ docker run -it --cpuset-mems="1,3" ubuntu:14.04 /bin/bash
  1014  
  1015  This example restricts the processes in the container to only use memory from
  1016  memory nodes 1 and 3.
  1017  
  1018      $ docker run -it --cpuset-mems="0-2" ubuntu:14.04 /bin/bash
  1019  
  1020  This example restricts the processes in the container to only use memory from
  1021  memory nodes 0, 1 and 2.
  1022  
  1023  ### CPU quota constraint
  1024  
  1025  The `--cpu-quota` flag limits the container's CPU usage. The default 0 value
  1026  allows the container to take 100% of a CPU resource (1 CPU). The CFS (Completely Fair
  1027  Scheduler) handles resource allocation for executing processes and is default
  1028  Linux Scheduler used by the kernel. Set this value to 50000 to limit the container
  1029  to 50% of a CPU resource. For multiple CPUs, adjust the `--cpu-quota` as necessary.
  1030  For more information, see the [CFS documentation on bandwidth limiting](https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt).
  1031  
  1032  ### Block IO bandwidth (Blkio) constraint
  1033  
  1034  By default, all containers get the same proportion of block IO bandwidth
  1035  (blkio). This proportion is 500. To modify this proportion, change the
  1036  container's blkio weight relative to the weighting of all other running
  1037  containers using the `--blkio-weight` flag.
  1038  
  1039  > **Note:** The blkio weight setting is only available for direct IO. Buffered IO
  1040  > is not currently supported.
  1041  
  1042  The `--blkio-weight` flag can set the weighting to a value between 10 to 1000.
  1043  For example, the commands below create two containers with different blkio
  1044  weight:
  1045  
  1046      $ docker run -it --name c1 --blkio-weight 300 ubuntu:14.04 /bin/bash
  1047      $ docker run -it --name c2 --blkio-weight 600 ubuntu:14.04 /bin/bash
  1048  
  1049  If you do block IO in the two containers at the same time, by, for example:
  1050  
  1051      $ time dd if=/mnt/zerofile of=test.out bs=1M count=1024 oflag=direct
  1052  
  1053  You'll find that the proportion of time is the same as the proportion of blkio
  1054  weights of the two containers.
  1055  
  1056  The `--blkio-weight-device="DEVICE_NAME:WEIGHT"` flag sets a specific device weight.
  1057  The `DEVICE_NAME:WEIGHT` is a string containing a colon-separated device name and weight.
  1058  For example, to set `/dev/sda` device weight to `200`:
  1059  
  1060      $ docker run -it \
  1061          --blkio-weight-device "/dev/sda:200" \
  1062          ubuntu
  1063  
  1064  If you specify both the `--blkio-weight` and `--blkio-weight-device`, Docker
  1065  uses the `--blkio-weight` as the default weight and uses `--blkio-weight-device`
  1066  to override this default with a new value on a specific device.
  1067  The following example uses a default weight of `300` and overrides this default
  1068  on `/dev/sda` setting that weight to `200`:
  1069  
  1070      $ docker run -it \
  1071          --blkio-weight 300 \
  1072          --blkio-weight-device "/dev/sda:200" \
  1073          ubuntu
  1074  
  1075  The `--device-read-bps` flag limits the read rate (bytes per second) from a device.
  1076  For example, this command creates a container and limits the read rate to `1mb`
  1077  per second from `/dev/sda`:
  1078  
  1079      $ docker run -it --device-read-bps /dev/sda:1mb ubuntu
  1080  
  1081  The `--device-write-bps` flag limits the write rate (bytes per second)to a device.
  1082  For example, this command creates a container and limits the write rate to `1mb`
  1083  per second for `/dev/sda`:
  1084  
  1085      $ docker run -it --device-write-bps /dev/sda:1mb ubuntu
  1086  
  1087  Both flags take limits in the `<device-path>:<limit>[unit]` format. Both read
  1088  and write rates must be a positive integer. You can specify the rate in `kb`
  1089  (kilobytes), `mb` (megabytes), or `gb` (gigabytes).
  1090  
  1091  The `--device-read-iops` flag limits read rate (IO per second) from a device.
  1092  For example, this command creates a container and limits the read rate to
  1093  `1000` IO per second from `/dev/sda`:
  1094  
  1095      $ docker run -ti --device-read-iops /dev/sda:1000 ubuntu
  1096  
  1097  The `--device-write-iops` flag limits write rate (IO per second) to a device.
  1098  For example, this command creates a container and limits the write rate to
  1099  `1000` IO per second to `/dev/sda`:
  1100  
  1101      $ docker run -ti --device-write-iops /dev/sda:1000 ubuntu
  1102  
  1103  Both flags take limits in the `<device-path>:<limit>` format. Both read and
  1104  write rates must be a positive integer.
  1105  
  1106  ## Additional groups
  1107      --group-add: Add additional groups to run as
  1108  
  1109  By default, the docker container process runs with the supplementary groups looked
  1110  up for the specified user. If one wants to add more to that list of groups, then
  1111  one can use this flag:
  1112  
  1113      $ docker run --rm --group-add audio --group-add nogroup --group-add 777 busybox id
  1114      uid=0(root) gid=0(root) groups=10(wheel),29(audio),99(nogroup),777
  1115  
  1116  ## Runtime privilege and Linux capabilities
  1117  
  1118      --cap-add: Add Linux capabilities
  1119      --cap-drop: Drop Linux capabilities
  1120      --privileged=false: Give extended privileges to this container
  1121      --device=[]: Allows you to run devices inside the container without the --privileged flag.
  1122  
  1123  By default, Docker containers are "unprivileged" and cannot, for
  1124  example, run a Docker daemon inside a Docker container. This is because
  1125  by default a container is not allowed to access any devices, but a
  1126  "privileged" container is given access to all devices (see
  1127  the documentation on [cgroups devices](https://www.kernel.org/doc/Documentation/cgroup-v1/devices.txt)).
  1128  
  1129  When the operator executes `docker run --privileged`, Docker will enable
  1130  to access to all devices on the host as well as set some configuration
  1131  in AppArmor or SELinux to allow the container nearly all the same access to the
  1132  host as processes running outside containers on the host. Additional
  1133  information about running with `--privileged` is available on the
  1134  [Docker Blog](http://blog.docker.com/2013/09/docker-can-now-run-within-docker/).
  1135  
  1136  If you want to limit access to a specific device or devices you can use
  1137  the `--device` flag. It allows you to specify one or more devices that
  1138  will be accessible within the container.
  1139  
  1140      $ docker run --device=/dev/snd:/dev/snd ...
  1141  
  1142  By default, the container will be able to `read`, `write`, and `mknod` these devices.
  1143  This can be overridden using a third `:rwm` set of options to each `--device` flag:
  1144  
  1145      $ docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk  /dev/xvdc
  1146  
  1147      Command (m for help): q
  1148      $ docker run --device=/dev/sda:/dev/xvdc:r --rm -it ubuntu fdisk  /dev/xvdc
  1149      You will not be able to write the partition table.
  1150  
  1151      Command (m for help): q
  1152  
  1153      $ docker run --device=/dev/sda:/dev/xvdc:w --rm -it ubuntu fdisk  /dev/xvdc
  1154          crash....
  1155  
  1156      $ docker run --device=/dev/sda:/dev/xvdc:m --rm -it ubuntu fdisk  /dev/xvdc
  1157      fdisk: unable to open /dev/xvdc: Operation not permitted
  1158  
  1159  In addition to `--privileged`, the operator can have fine grain control over the
  1160  capabilities using `--cap-add` and `--cap-drop`. By default, Docker has a default
  1161  list of capabilities that are kept. The following table lists the Linux capability
  1162  options which are allowed by default and can be dropped.
  1163  
  1164  | Capability Key   | Capability Description                                                                                                        |
  1165  | ---------------- | ----------------------------------------------------------------------------------------------------------------------------- |
  1166  | SETPCAP          | Modify process capabilities.                                                                                                  |
  1167  | MKNOD            | Create special files using mknod(2).                                                                                          |
  1168  | AUDIT_WRITE      | Write records to kernel auditing log.                                                                                         |
  1169  | CHOWN            | Make arbitrary changes to file UIDs and GIDs (see chown(2)).                                                                  |
  1170  | NET_RAW          | Use RAW and PACKET sockets.                                                                                                   |
  1171  | DAC_OVERRIDE     | Bypass file read, write, and execute permission checks.                                                                       |
  1172  | FOWNER           | Bypass permission checks on operations that normally require the file system UID of the process to match the UID of the file. |
  1173  | FSETID           | Don't clear set-user-ID and set-group-ID permission bits when a file is modified.                                             |
  1174  | KILL             | Bypass permission checks for sending signals.                                                                                 |
  1175  | SETGID           | Make arbitrary manipulations of process GIDs and supplementary GID list.                                                      |
  1176  | SETUID           | Make arbitrary manipulations of process UIDs.                                                                                 |
  1177  | NET_BIND_SERVICE | Bind a socket to internet domain privileged ports (port numbers less than 1024).                                              |
  1178  | SYS_CHROOT       | Use chroot(2), change root directory.                                                                                         |
  1179  | SETFCAP          | Set file capabilities.                                                                                                        |
  1180  
  1181  The next table shows the capabilities which are not granted by default and may be added.
  1182  
  1183  | Capability Key   | Capability Description                                                                                                        |
  1184  | ---------------- | ----------------------------------------------------------------------------------------------------------------------------- |
  1185  | SYS_MODULE       | Load and unload kernel modules.                                                                                               |
  1186  | SYS_RAWIO        | Perform I/O port operations (iopl(2) and ioperm(2)).                                                                          |
  1187  | SYS_PACCT        | Use acct(2), switch process accounting on or off.                                                                             |
  1188  | SYS_ADMIN        | Perform a range of system administration operations.                                                                          |
  1189  | SYS_NICE         | Raise process nice value (nice(2), setpriority(2)) and change the nice value for arbitrary processes.                         |
  1190  | SYS_RESOURCE     | Override resource Limits.                                                                                                     |
  1191  | SYS_TIME         | Set system clock (settimeofday(2), stime(2), adjtimex(2)); set real-time (hardware) clock.                                    |
  1192  | SYS_TTY_CONFIG   | Use vhangup(2); employ various privileged ioctl(2) operations on virtual terminals.                                           |
  1193  | AUDIT_CONTROL    | Enable and disable kernel auditing; change auditing filter rules; retrieve auditing status and filtering rules.               |
  1194  | MAC_OVERRIDE     | Allow MAC configuration or state changes. Implemented for the Smack LSM.                                                      |
  1195  | MAC_ADMIN        | Override Mandatory Access Control (MAC). Implemented for the Smack Linux Security Module (LSM).                               |
  1196  | NET_ADMIN        | Perform various network-related operations.                                                                                   |
  1197  | SYSLOG           | Perform privileged syslog(2) operations.                                                                                      |
  1198  | DAC_READ_SEARCH  | Bypass file read permission checks and directory read and execute permission checks.                                          |
  1199  | LINUX_IMMUTABLE  | Set the FS_APPEND_FL and FS_IMMUTABLE_FL i-node flags.                                                                        |
  1200  | NET_BROADCAST    | Make socket broadcasts, and listen to multicasts.                                                                             |
  1201  | IPC_LOCK         | Lock memory (mlock(2), mlockall(2), mmap(2), shmctl(2)).                                                                      |
  1202  | IPC_OWNER        | Bypass permission checks for operations on System V IPC objects.                                                              |
  1203  | SYS_PTRACE       | Trace arbitrary processes using ptrace(2).                                                                                    |
  1204  | SYS_BOOT         | Use reboot(2) and kexec_load(2), reboot and load a new kernel for later execution.                                            |
  1205  | LEASE            | Establish leases on arbitrary files (see fcntl(2)).                                                                           |
  1206  | WAKE_ALARM       | Trigger something that will wake up the system.                                                                               |
  1207  | BLOCK_SUSPEND    | Employ features that can block system suspend.                                                                                |
  1208  
  1209  Further reference information is available on the [capabilities(7) - Linux man page](http://man7.org/linux/man-pages/man7/capabilities.7.html)
  1210  
  1211  Both flags support the value `ALL`, so if the
  1212  operator wants to have all capabilities but `MKNOD` they could use:
  1213  
  1214      $ docker run --cap-add=ALL --cap-drop=MKNOD ...
  1215  
  1216  For interacting with the network stack, instead of using `--privileged` they
  1217  should use `--cap-add=NET_ADMIN` to modify the network interfaces.
  1218  
  1219      $ docker run -it --rm  ubuntu:14.04 ip link add dummy0 type dummy
  1220      RTNETLINK answers: Operation not permitted
  1221      $ docker run -it --rm --cap-add=NET_ADMIN ubuntu:14.04 ip link add dummy0 type dummy
  1222  
  1223  To mount a FUSE based filesystem, you need to combine both `--cap-add` and
  1224  `--device`:
  1225  
  1226      $ docker run --rm -it --cap-add SYS_ADMIN sshfs sshfs sven@10.10.10.20:/home/sven /mnt
  1227      fuse: failed to open /dev/fuse: Operation not permitted
  1228      $ docker run --rm -it --device /dev/fuse sshfs sshfs sven@10.10.10.20:/home/sven /mnt
  1229      fusermount: mount failed: Operation not permitted
  1230      $ docker run --rm -it --cap-add SYS_ADMIN --device /dev/fuse sshfs
  1231      # sshfs sven@10.10.10.20:/home/sven /mnt
  1232      The authenticity of host '10.10.10.20 (10.10.10.20)' can't be established.
  1233      ECDSA key fingerprint is 25:34:85:75:25:b0:17:46:05:19:04:93:b5:dd:5f:c6.
  1234      Are you sure you want to continue connecting (yes/no)? yes
  1235      sven@10.10.10.20's password:
  1236      root@30aa0cfaf1b5:/# ls -la /mnt/src/docker
  1237      total 1516
  1238      drwxrwxr-x 1 1000 1000   4096 Dec  4 06:08 .
  1239      drwxrwxr-x 1 1000 1000   4096 Dec  4 11:46 ..
  1240      -rw-rw-r-- 1 1000 1000     16 Oct  8 00:09 .dockerignore
  1241      -rwxrwxr-x 1 1000 1000    464 Oct  8 00:09 .drone.yml
  1242      drwxrwxr-x 1 1000 1000   4096 Dec  4 06:11 .git
  1243      -rw-rw-r-- 1 1000 1000    461 Dec  4 06:08 .gitignore
  1244      ....
  1245  
  1246  The default seccomp profile will adjust to the selected capabilities, in order to allow
  1247  use of facilities allowed by the capabilities, so you should not have to adjust this,
  1248  since Docker 1.12. In Docker 1.10 and 1.11 this did not happen and it may be necessary
  1249  to use a custom seccomp profile or use `--security-opt seccomp=unconfined` when adding
  1250  capabilities.
  1251  
  1252  ## Logging drivers (--log-driver)
  1253  
  1254  The container can have a different logging driver than the Docker daemon. Use
  1255  the `--log-driver=VALUE` with the `docker run` command to configure the
  1256  container's logging driver. The following options are supported:
  1257  
  1258  | Driver      | Description                                                                                                                   |
  1259  | ----------- | ----------------------------------------------------------------------------------------------------------------------------- |
  1260  | `none`      | Disables any logging for the container. `docker logs` won't be available with this driver.                                    |
  1261  | `json-file` | Default logging driver for Docker. Writes JSON messages to file.  No logging options are supported for this driver.           |
  1262  | `syslog`    | Syslog logging driver for Docker. Writes log messages to syslog.                                                              |
  1263  | `journald`  | Journald logging driver for Docker. Writes log messages to `journald`.                                                        |
  1264  | `gelf`      | Graylog Extended Log Format (GELF) logging driver for Docker. Writes log messages to a GELF endpoint likeGraylog or Logstash. |
  1265  | `fluentd`   | Fluentd logging driver for Docker. Writes log messages to `fluentd` (forward input).                                          |
  1266  | `awslogs`   | Amazon CloudWatch Logs logging driver for Docker. Writes log messages to Amazon CloudWatch Logs                               |
  1267  | `splunk`    | Splunk logging driver for Docker. Writes log messages to `splunk` using Event Http Collector.                                 |
  1268  
  1269  The `docker logs` command is available only for the `json-file` and `journald`
  1270  logging drivers.  For detailed information on working with logging drivers, see
  1271  [Configure a logging driver](https://docs.docker.com/engine/admin/logging/overview/).
  1272  
  1273  
  1274  ## Overriding Dockerfile image defaults
  1275  
  1276  When a developer builds an image from a [*Dockerfile*](builder.md)
  1277  or when she commits it, the developer can set a number of default parameters
  1278  that take effect when the image starts up as a container.
  1279  
  1280  Four of the Dockerfile commands cannot be overridden at runtime: `FROM`,
  1281  `MAINTAINER`, `RUN`, and `ADD`. Everything else has a corresponding override
  1282  in `docker run`. We'll go through what the developer might have set in each
  1283  Dockerfile instruction and how the operator can override that setting.
  1284  
  1285   - [CMD (Default Command or Options)](#cmd-default-command-or-options)
  1286   - [ENTRYPOINT (Default Command to Execute at Runtime)](
  1287      #entrypoint-default-command-to-execute-at-runtime)
  1288   - [EXPOSE (Incoming Ports)](#expose-incoming-ports)
  1289   - [ENV (Environment Variables)](#env-environment-variables)
  1290   - [HEALTHCHECK](#healthcheck)
  1291   - [VOLUME (Shared Filesystems)](#volume-shared-filesystems)
  1292   - [USER](#user)
  1293   - [WORKDIR](#workdir)
  1294  
  1295  ### CMD (default command or options)
  1296  
  1297  Recall the optional `COMMAND` in the Docker
  1298  commandline:
  1299  
  1300      $ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
  1301  
  1302  This command is optional because the person who created the `IMAGE` may
  1303  have already provided a default `COMMAND` using the Dockerfile `CMD`
  1304  instruction. As the operator (the person running a container from the
  1305  image), you can override that `CMD` instruction just by specifying a new
  1306  `COMMAND`.
  1307  
  1308  If the image also specifies an `ENTRYPOINT` then the `CMD` or `COMMAND`
  1309  get appended as arguments to the `ENTRYPOINT`.
  1310  
  1311  ### ENTRYPOINT (default command to execute at runtime)
  1312  
  1313      --entrypoint="": Overwrite the default entrypoint set by the image
  1314  
  1315  The `ENTRYPOINT` of an image is similar to a `COMMAND` because it
  1316  specifies what executable to run when the container starts, but it is
  1317  (purposely) more difficult to override. The `ENTRYPOINT` gives a
  1318  container its default nature or behavior, so that when you set an
  1319  `ENTRYPOINT` you can run the container *as if it were that binary*,
  1320  complete with default options, and you can pass in more options via the
  1321  `COMMAND`. But, sometimes an operator may want to run something else
  1322  inside the container, so you can override the default `ENTRYPOINT` at
  1323  runtime by using a string to specify the new `ENTRYPOINT`. Here is an
  1324  example of how to run a shell in a container that has been set up to
  1325  automatically run something else (like `/usr/bin/redis-server`):
  1326  
  1327      $ docker run -it --entrypoint /bin/bash example/redis
  1328  
  1329  or two examples of how to pass more parameters to that ENTRYPOINT:
  1330  
  1331      $ docker run -it --entrypoint /bin/bash example/redis -c ls -l
  1332      $ docker run -it --entrypoint /usr/bin/redis-cli example/redis --help
  1333  
  1334  You can reset a containers entrypoint by passing an empty string, for example:
  1335  
  1336      $ docker run -it --entrypoint="" mysql bash
  1337  
  1338  > **Note**: Passing `--entrypoint` will clear out any default command set on the
  1339  > image (i.e. any `CMD` instruction in the Dockerfile used to build it).
  1340  
  1341  ### EXPOSE (incoming ports)
  1342  
  1343  The following `run` command options work with container networking:
  1344  
  1345      --expose=[]: Expose a port or a range of ports inside the container.
  1346                   These are additional to those exposed by the `EXPOSE` instruction
  1347      -P         : Publish all exposed ports to the host interfaces
  1348      -p=[]      : Publish a container᾿s port or a range of ports to the host
  1349                     format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
  1350                     Both hostPort and containerPort can be specified as a
  1351                     range of ports. When specifying ranges for both, the
  1352                     number of container ports in the range must match the
  1353                     number of host ports in the range, for example:
  1354                         -p 1234-1236:1234-1236/tcp
  1355  
  1356                     When specifying a range for hostPort only, the
  1357                     containerPort must not be a range.  In this case the
  1358                     container port is published somewhere within the
  1359                     specified hostPort range. (e.g., `-p 1234-1236:1234/tcp`)
  1360  
  1361                     (use 'docker port' to see the actual mapping)
  1362  
  1363      --link=""  : Add link to another container (<name or id>:alias or <name or id>)
  1364  
  1365  With the exception of the `EXPOSE` directive, an image developer hasn't
  1366  got much control over networking. The `EXPOSE` instruction defines the
  1367  initial incoming ports that provide services. These ports are available
  1368  to processes inside the container. An operator can use the `--expose`
  1369  option to add to the exposed ports.
  1370  
  1371  To expose a container's internal port, an operator can start the
  1372  container with the `-P` or `-p` flag. The exposed port is accessible on
  1373  the host and the ports are available to any client that can reach the
  1374  host.
  1375  
  1376  The `-P` option publishes all the ports to the host interfaces. Docker
  1377  binds each exposed port to a random port on the host. The range of
  1378  ports are within an *ephemeral port range* defined by
  1379  `/proc/sys/net/ipv4/ip_local_port_range`. Use the `-p` flag to
  1380  explicitly map a single port or range of ports.
  1381  
  1382  The port number inside the container (where the service listens) does
  1383  not need to match the port number exposed on the outside of the
  1384  container (where clients connect). For example, inside the container an
  1385  HTTP service is listening on port 80 (and so the image developer
  1386  specifies `EXPOSE 80` in the Dockerfile). At runtime, the port might be
  1387  bound to 42800 on the host. To find the mapping between the host ports
  1388  and the exposed ports, use `docker port`.
  1389  
  1390  If the operator uses `--link` when starting a new client container in the
  1391  default bridge network, then the client container can access the exposed
  1392  port via a private networking interface.
  1393  If `--link` is used when starting a container in a user-defined network as
  1394  described in [*Docker network overview*](https://docs.docker.com/engine/userguide/networking/),
  1395  it will provide a named alias for the container being linked to.
  1396  
  1397  ### ENV (environment variables)
  1398  
  1399  Docker automatically sets some environment variables when creating a Linux
  1400  container. Docker does not set any environment variables when creating a Windows
  1401  container.
  1402  
  1403  The following environment variables are set for Linux containers:
  1404  
  1405  | Variable | Value |
  1406  | -------- | ----- |
  1407  | `HOME` | Set based on the value of `USER` |
  1408  | `HOSTNAME` | The hostname associated with the container |
  1409  | `PATH` | Includes popular directories, such as `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin` |
  1410  | `TERM` | `xterm` if the container is allocated a pseudo-TTY |
  1411  
  1412  
  1413  Additionally, the operator can **set any environment variable** in the
  1414  container by using one or more `-e` flags, even overriding those mentioned
  1415  above, or already defined by the developer with a Dockerfile `ENV`:
  1416  
  1417  ```bash
  1418  $ docker run -e "deep=purple" --rm alpine env
  1419  PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  1420  HOSTNAME=d2219b854598
  1421  deep=purple
  1422  HOME=/root
  1423  ```
  1424  
  1425  ```PowerShell
  1426  PS C:\> docker run --rm -e "foo=bar" microsoft/nanoserver cmd /s /c set
  1427  ALLUSERSPROFILE=C:\ProgramData
  1428  APPDATA=C:\Users\ContainerAdministrator\AppData\Roaming
  1429  CommonProgramFiles=C:\Program Files\Common Files
  1430  CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
  1431  CommonProgramW6432=C:\Program Files\Common Files
  1432  COMPUTERNAME=C2FAEFCC8253
  1433  ComSpec=C:\Windows\system32\cmd.exe
  1434  foo=bar
  1435  LOCALAPPDATA=C:\Users\ContainerAdministrator\AppData\Local
  1436  NUMBER_OF_PROCESSORS=8
  1437  OS=Windows_NT
  1438  Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Users\ContainerAdministrator\AppData\Local\Microsoft\WindowsApps
  1439  PATHEXT=.COM;.EXE;.BAT;.CMD
  1440  PROCESSOR_ARCHITECTURE=AMD64
  1441  PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 62 Stepping 4, GenuineIntel
  1442  PROCESSOR_LEVEL=6
  1443  PROCESSOR_REVISION=3e04
  1444  ProgramData=C:\ProgramData
  1445  ProgramFiles=C:\Program Files
  1446  ProgramFiles(x86)=C:\Program Files (x86)
  1447  ProgramW6432=C:\Program Files
  1448  PROMPT=$P$G
  1449  PUBLIC=C:\Users\Public
  1450  SystemDrive=C:
  1451  SystemRoot=C:\Windows
  1452  TEMP=C:\Users\ContainerAdministrator\AppData\Local\Temp
  1453  TMP=C:\Users\ContainerAdministrator\AppData\Local\Temp
  1454  USERDOMAIN=User Manager
  1455  USERNAME=ContainerAdministrator
  1456  USERPROFILE=C:\Users\ContainerAdministrator
  1457  windir=C:\Windows
  1458  ```
  1459  
  1460  Similarly the operator can set the **HOSTNAME** (Linux) or **COMPUTERNAME** (Windows) with `-h`.
  1461  
  1462  ### HEALTHCHECK
  1463  
  1464  ```
  1465    --health-cmd            Command to run to check health
  1466    --health-interval       Time between running the check
  1467    --health-retries        Consecutive failures needed to report unhealthy
  1468    --health-timeout        Maximum time to allow one check to run
  1469    --no-healthcheck        Disable any container-specified HEALTHCHECK
  1470  ```
  1471  
  1472  Example:
  1473  
  1474      {% raw %}
  1475      $ docker run --name=test -d \
  1476          --health-cmd='stat /etc/passwd || exit 1' \
  1477          --health-interval=2s \
  1478          busybox sleep 1d
  1479      $ sleep 2; docker inspect --format='{{.State.Health.Status}}' test
  1480      healthy
  1481      $ docker exec test rm /etc/passwd
  1482      $ sleep 2; docker inspect --format='{{json .State.Health}}' test
  1483      {
  1484        "Status": "unhealthy",
  1485        "FailingStreak": 3,
  1486        "Log": [
  1487          {
  1488            "Start": "2016-05-25T17:22:04.635478668Z",
  1489            "End": "2016-05-25T17:22:04.7272552Z",
  1490            "ExitCode": 0,
  1491            "Output": "  File: /etc/passwd\n  Size: 334       \tBlocks: 8          IO Block: 4096   regular file\nDevice: 32h/50d\tInode: 12          Links: 1\nAccess: (0664/-rw-rw-r--)  Uid: (    0/    root)   Gid: (    0/    root)\nAccess: 2015-12-05 22:05:32.000000000\nModify: 2015..."
  1492          },
  1493          {
  1494            "Start": "2016-05-25T17:22:06.732900633Z",
  1495            "End": "2016-05-25T17:22:06.822168935Z",
  1496            "ExitCode": 0,
  1497            "Output": "  File: /etc/passwd\n  Size: 334       \tBlocks: 8          IO Block: 4096   regular file\nDevice: 32h/50d\tInode: 12          Links: 1\nAccess: (0664/-rw-rw-r--)  Uid: (    0/    root)   Gid: (    0/    root)\nAccess: 2015-12-05 22:05:32.000000000\nModify: 2015..."
  1498          },
  1499          {
  1500            "Start": "2016-05-25T17:22:08.823956535Z",
  1501            "End": "2016-05-25T17:22:08.897359124Z",
  1502            "ExitCode": 1,
  1503            "Output": "stat: can't stat '/etc/passwd': No such file or directory\n"
  1504          },
  1505          {
  1506            "Start": "2016-05-25T17:22:10.898802931Z",
  1507            "End": "2016-05-25T17:22:10.969631866Z",
  1508            "ExitCode": 1,
  1509            "Output": "stat: can't stat '/etc/passwd': No such file or directory\n"
  1510          },
  1511          {
  1512            "Start": "2016-05-25T17:22:12.971033523Z",
  1513            "End": "2016-05-25T17:22:13.082015516Z",
  1514            "ExitCode": 1,
  1515            "Output": "stat: can't stat '/etc/passwd': No such file or directory\n"
  1516          }
  1517        ]
  1518      }
  1519      {% endraw %}
  1520  
  1521  The health status is also displayed in the `docker ps` output.
  1522  
  1523  ### TMPFS (mount tmpfs filesystems)
  1524  
  1525  ```bash
  1526  --tmpfs=[]: Create a tmpfs mount with: container-dir[:<options>],
  1527              where the options are identical to the Linux
  1528              'mount -t tmpfs -o' command.
  1529  ```
  1530  
  1531  The example below mounts an empty tmpfs into the container with the `rw`,
  1532  `noexec`, `nosuid`, and `size=65536k` options.
  1533  
  1534      $ docker run -d --tmpfs /run:rw,noexec,nosuid,size=65536k my_image
  1535  
  1536  ### VOLUME (shared filesystems)
  1537  
  1538      -v, --volume=[host-src:]container-dest[:<options>]: Bind mount a volume.
  1539      The comma-delimited `options` are [rw|ro], [z|Z],
  1540      [[r]shared|[r]slave|[r]private], and [nocopy].
  1541      The 'host-src' is an absolute path or a name value.
  1542  
  1543      If neither 'rw' or 'ro' is specified then the volume is mounted in
  1544      read-write mode.
  1545  
  1546      The `nocopy` modes is used to disable automatic copying requested volume
  1547      path in the container to the volume storage location.
  1548      For named volumes, `copy` is the default mode. Copy modes are not supported
  1549      for bind-mounted volumes.
  1550  
  1551      --volumes-from="": Mount all volumes from the given container(s)
  1552  
  1553  > **Note**:
  1554  > When using systemd to manage the Docker daemon's start and stop, in the systemd
  1555  > unit file there is an option to control mount propagation for the Docker daemon
  1556  > itself, called `MountFlags`. The value of this setting may cause Docker to not
  1557  > see mount propagation changes made on the mount point. For example, if this value
  1558  > is `slave`, you may not be able to use the `shared` or `rshared` propagation on
  1559  > a volume.
  1560  
  1561  The volumes commands are complex enough to have their own documentation
  1562  in section [*Manage data in
  1563  containers*](https://docs.docker.com/engine/tutorials/dockervolumes/). A developer can define
  1564  one or more `VOLUME`'s associated with an image, but only the operator
  1565  can give access from one container to another (or from a container to a
  1566  volume mounted on the host).
  1567  
  1568  The `container-dest` must always be an absolute path such as `/src/docs`.
  1569  The `host-src` can either be an absolute path or a `name` value. If you
  1570  supply an absolute path for the `host-dir`, Docker bind-mounts to the path
  1571  you specify. If you supply a `name`, Docker creates a named volume by that `name`.
  1572  
  1573  A `name` value must start with an alphanumeric character,
  1574  followed by `a-z0-9`, `_` (underscore), `.` (period) or `-` (hyphen).
  1575  An absolute path starts with a `/` (forward slash).
  1576  
  1577  For example, you can specify either `/foo` or `foo` for a `host-src` value.
  1578  If you supply the `/foo` value, Docker creates a bind-mount. If you supply
  1579  the `foo` specification, Docker creates a named volume.
  1580  
  1581  ### USER
  1582  
  1583  `root` (id = 0) is the default user within a container. The image developer can
  1584  create additional users. Those users are accessible by name.  When passing a numeric
  1585  ID, the user does not have to exist in the container.
  1586  
  1587  The developer can set a default user to run the first process with the
  1588  Dockerfile `USER` instruction. When starting a container, the operator can override
  1589  the `USER` instruction by passing the `-u` option.
  1590  
  1591      -u="", --user="": Sets the username or UID used and optionally the groupname or GID for the specified command.
  1592  
  1593      The followings examples are all valid:
  1594      --user=[ user | user:group | uid | uid:gid | user:gid | uid:group ]
  1595  
  1596  > **Note:** if you pass a numeric uid, it must be in the range of 0-2147483647.
  1597  
  1598  ### WORKDIR
  1599  
  1600  The default working directory for running binaries within a container is the
  1601  root directory (`/`), but the developer can set a different default with the
  1602  Dockerfile `WORKDIR` command. The operator can override this with:
  1603  
  1604      -w="": Working directory inside the container