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