github.com/walkingsparrow/docker@v1.4.2-0.20151218153551-b708a2249bfa/man/docker-run.1.md (about)

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