github.com/slene/docker@v1.8.0-rc1/docs/reference/run.md (about)

     1  <!--[metadata]>
     2  +++
     3  title = "Docker run reference"
     4  description = "Configure containers at runtime"
     5  keywords = ["docker, run, configure,  runtime"]
     6  [menu.main]
     7  parent = "mn_reference"
     8  +++
     9  <![end-metadata]-->
    10  
    11  <!-- TODO (@thaJeztah) define more flexible table/td classes -->
    12  <style>
    13  .content-body table .no-wrap {
    14      white-space: nowrap;
    15  }
    16  </style>
    17  # Docker run reference
    18  
    19  **Docker runs processes in isolated containers**. When an operator
    20  executes `docker run`, she starts a process with its own file system,
    21  its own networking, and its own isolated process tree.  The
    22  [*Image*](/terms/image/#image) which starts the process may define
    23  defaults related to the binary to run, the networking to expose, and
    24  more, but `docker run` gives final control to the operator who starts
    25  the container from the image. That's the main reason
    26  [*run*](/reference/commandline/cli/#run) has more options than any
    27  other `docker` command.
    28  
    29  ## General form
    30  
    31  The basic `docker run` command takes this form:
    32  
    33      $ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
    34  
    35  To learn how to interpret the types of `[OPTIONS]`,
    36  see [*Option types*](/reference/commandline/cli/#option-types).
    37  
    38  The `run` options control the image's runtime behavior in a container. These
    39  settings affect:
    40  
    41   * detached or foreground running
    42   * container identification
    43   * network settings
    44   * runtime constraints on CPU and memory
    45   * privileges and LXC configuration
    46  
    47  An image developer may set defaults for these same settings when they create the
    48  image using the `docker build` command. Operators, however, can override all
    49  defaults set by the developer using the `run` options.  And, operators can also
    50  override nearly all the defaults set by the Docker runtime itself.
    51  
    52  Finally, depending on your Docker system configuration, you may be required to
    53  preface each `docker` command with `sudo`. To avoid having to use `sudo` with
    54  the `docker` command, your system administrator can create a Unix group called
    55  `docker` and add users to it. For more information about this configuration,
    56  refer to the Docker installation documentation for your operating system.
    57  
    58  ## Operator exclusive options
    59  
    60  Only the operator (the person executing `docker run`) can set the
    61  following options.
    62  
    63   - [Detached vs Foreground](#detached-vs-foreground)
    64       - [Detached (-d)](#detached-d)
    65       - [Foreground](#foreground)
    66   - [Container Identification](#container-identification)
    67       - [Name (--name)](#name-name)
    68       - [PID Equivalent](#pid-equivalent)
    69   - [IPC Settings (--ipc)](#ipc-settings-ipc)
    70   - [Network Settings](#network-settings)
    71   - [Restart Policies (--restart)](#restart-policies-restart)
    72   - [Clean Up (--rm)](#clean-up-rm)
    73   - [Runtime Constraints on CPU and Memory](#runtime-constraints-on-cpu-and-memory)
    74   - [Runtime Privilege, Linux Capabilities, and LXC Configuration](#runtime-privilege-linux-capabilities-and-lxc-configuration)
    75  
    76  ## Detached vs foreground
    77  
    78  When starting a Docker container, you must first decide if you want to
    79  run the container in the background in a "detached" mode or in the
    80  default foreground mode:
    81  
    82      -d=false: Detached mode: Run container in the background, print new container id
    83  
    84  ### Detached (-d)
    85  
    86  In detached mode (`-d=true` or just `-d`), all I/O should be done
    87  through network connections or shared volumes because the container is
    88  no longer listening to the command line where you executed `docker run`.
    89  You can reattach to a detached container with `docker`
    90  [*attach*](/reference/commandline/cli/#attach). If you choose to run a
    91  container in the detached mode, then you cannot use the `--rm` option.
    92  
    93  ### Foreground
    94  
    95  In foreground mode (the default when `-d` is not specified), `docker
    96  run` can start the process in the container and attach the console to
    97  the process's standard input, output, and standard error. It can even
    98  pretend to be a TTY (this is what most command line executables expect)
    99  and pass along signals. All of that is configurable:
   100  
   101      -a=[]           : Attach to `STDIN`, `STDOUT` and/or `STDERR`
   102      -t=false        : Allocate a pseudo-tty
   103      --sig-proxy=true: Proxify all received signal to the process (non-TTY mode only)
   104      -i=false        : Keep STDIN open even if not attached
   105  
   106  If you do not specify `-a` then Docker will [attach all standard
   107  streams]( https://github.com/docker/docker/blob/
   108  75a7f4d90cde0295bcfb7213004abce8d4779b75/commands.go#L1797). You can
   109  specify to which of the three standard streams (`STDIN`, `STDOUT`,
   110  `STDERR`) you'd like to connect instead, as in:
   111  
   112      $ docker run -a stdin -a stdout -i -t ubuntu /bin/bash
   113  
   114  For interactive processes (like a shell), you must use `-i -t` together in
   115  order to allocate a tty for the container process. `-i -t` is often written `-it`
   116  as you'll see in later examples.  Specifying `-t` is forbidden when the client
   117  standard output is redirected or piped, such as in:
   118  `echo test | docker run -i busybox cat`.
   119  
   120  >**Note**: A process running as PID 1 inside a container is treated
   121  >specially by Linux: it ignores any signal with the default action.
   122  >So, the process will not terminate on `SIGINT` or `SIGTERM` unless it is
   123  >coded to do so.
   124  
   125  ## Container identification
   126  
   127  ### Name (--name)
   128  
   129  The operator can identify a container in three ways:
   130  
   131  -   UUID long identifier
   132      ("f78375b1c487e03c9438c729345e54db9d20cfa2ac1fc3494b6eb60872e74778")
   133  -   UUID short identifier ("f78375b1c487")
   134  -   Name ("evil_ptolemy")
   135  
   136  The UUID identifiers come from the Docker daemon, and if you do not
   137  assign a name to the container with `--name` then the daemon will also
   138  generate a random string name too. The name can become a handy way to
   139  add meaning to a container since you can use this name when defining
   140  [*links*](/userguide/dockerlinks) (or any
   141  other place you need to identify a container). This works for both
   142  background and foreground Docker containers.
   143  
   144  ### PID equivalent
   145  
   146  Finally, to help with automation, you can have Docker write the
   147  container ID out to a file of your choosing. This is similar to how some
   148  programs might write out their process ID to a file (you've seen them as
   149  PID files):
   150  
   151      --cidfile="": Write the container ID to the file
   152  
   153  ### Image[:tag]
   154  
   155  While not strictly a means of identifying a container, you can specify a version of an
   156  image you'd like to run the container with by adding `image[:tag]` to the command. For
   157  example, `docker run ubuntu:14.04`.
   158  
   159  ### Image[@digest]
   160  
   161  Images using the v2 or later image format have a content-addressable identifier
   162  called a digest. As long as the input used to generate the image is unchanged,
   163  the digest value is predictable and referenceable.
   164  
   165  ## PID settings (--pid)
   166  
   167      --pid=""  : Set the PID (Process) Namespace mode for the container,
   168             'host': use the host's PID namespace inside the container
   169  
   170  By default, all containers have the PID namespace enabled.
   171  
   172  PID namespace provides separation of processes. The PID Namespace removes the
   173  view of the system processes, and allows process ids to be reused including
   174  pid 1.
   175  
   176  In certain cases you want your container to share the host's process namespace,
   177  basically allowing processes within the container to see all of the processes
   178  on the system.  For example, you could build a container with debugging tools
   179  like `strace` or `gdb`, but want to use these tools when debugging processes
   180  within the container.
   181  
   182      $ docker run --pid=host rhel7 strace -p 1234
   183  
   184  This command would allow you to use `strace` inside the container on pid 1234 on
   185  the host.
   186  
   187  ## UTS settings (--uts)
   188  
   189      --uts=""  : Set the UTS namespace mode for the container,
   190             'host': use the host's UTS namespace inside the container
   191  
   192  The UTS namespace is for setting the hostname and the domain that is visible
   193  to running processes in that namespace.  By default, all containers, including
   194  those with `--net=host`, have their own UTS namespace.  The `host` setting will
   195  result in the container using the same UTS namespace as the host.
   196  
   197  You may wish to share the UTS namespace with the host if you would like the
   198  hostname of the container to change as the hostname of the host changes.  A
   199  more advanced use case would be changing the host's hostname from a container.
   200  
   201  > **Note**: `--uts="host"` gives the container full access to change the
   202  > hostname of the host and is therefore considered insecure.
   203  
   204  ## IPC settings (--ipc)
   205  
   206      --ipc=""  : Set the IPC mode for the container,
   207                   'container:<name|id>': reuses another container's IPC namespace
   208                   'host': use the host's IPC namespace inside the container
   209  
   210  By default, all containers have the IPC namespace enabled.
   211  
   212  IPC (POSIX/SysV IPC) namespace provides separation of named shared memory
   213  segments, semaphores and message queues.
   214  
   215  Shared memory segments are used to accelerate inter-process communication at
   216  memory speed, rather than through pipes or through the network stack. Shared
   217  memory is commonly used by databases and custom-built (typically C/OpenMPI,
   218  C++/using boost libraries) high performance applications for scientific
   219  computing and financial services industries. If these types of applications
   220  are broken into multiple containers, you might need to share the IPC mechanisms
   221  of the containers.
   222  
   223  ## Network settings
   224  
   225      --dns=[]         : Set custom dns servers for the container
   226      --net="bridge"   : Set the Network mode for the container
   227                          'bridge': creates a new network stack for the container on the docker bridge
   228                          'none': no networking for this container
   229                          'container:<name|id>': reuses another container network stack
   230                          'host': use the host network stack inside the container
   231      --add-host=""    : Add a line to /etc/hosts (host:IP)
   232      --mac-address="" : Sets the container's Ethernet device's MAC address
   233  
   234  By default, all containers have networking enabled and they can make any
   235  outgoing connections. The operator can completely disable networking
   236  with `docker run --net none` which disables all incoming and outgoing
   237  networking. In cases like this, you would perform I/O through files or
   238  `STDIN` and `STDOUT` only.
   239  
   240  Publishing ports and linking to other containers will not work
   241  when `--net` is anything other than the default (bridge).
   242  
   243  Your container will use the same DNS servers as the host by default, but
   244  you can override this with `--dns`.
   245  
   246  By default, the MAC address is generated using the IP address allocated to the
   247  container. You can set the container's MAC address explicitly by providing a
   248  MAC address via the `--mac-address` parameter (format:`12:34:56:78:9a:bc`).
   249  
   250  Supported networking modes are:
   251  
   252  <table>
   253    <thead>
   254      <tr>
   255        <th class="no-wrap">Mode</th>
   256        <th>Description</th>
   257      </tr>
   258    </thead>
   259    <tbody>
   260      <tr>
   261        <td class="no-wrap"><strong>none</strong></td>
   262        <td>
   263          No networking in the container.
   264        </td>
   265      </tr>
   266      <tr>
   267        <td class="no-wrap"><strong>bridge</strong> (default)</td>
   268        <td>
   269          Connect the container to the bridge via veth interfaces.
   270        </td>
   271      </tr>
   272      <tr>
   273        <td class="no-wrap"><strong>host</strong></td>
   274        <td>
   275          Use the host's network stack inside the container.
   276        </td>
   277      </tr>
   278      <tr>
   279        <td class="no-wrap"><strong>container</strong>:&lt;name|id&gt;</td>
   280        <td>
   281          Use the network stack of another container, specified via
   282          its *name* or *id*.
   283        </td>
   284      </tr>
   285    </tbody>
   286  </table>
   287  
   288  #### Mode: none
   289  
   290  With the networking mode set to `none` a container will not have a
   291  access to any external routes.  The container will still have a
   292  `loopback` interface enabled in the container but it does not have any
   293  routes to external traffic.
   294  
   295  #### Mode: bridge
   296  
   297  With the networking mode set to `bridge` a container will use docker's
   298  default networking setup.  A bridge is setup on the host, commonly named
   299  `docker0`, and a pair of `veth` interfaces will be created for the
   300  container.  One side of the `veth` pair will remain on the host attached
   301  to the bridge while the other side of the pair will be placed inside the
   302  container's namespaces in addition to the `loopback` interface.  An IP
   303  address will be allocated for containers on the bridge's network and
   304  traffic will be routed though this bridge to the container.
   305  
   306  #### Mode: host
   307  
   308  With the networking mode set to `host` a container will share the host's
   309  network stack and all interfaces from the host will be available to the
   310  container.  The container's hostname will match the hostname on the host
   311  system.  Note that `--add-host` `--hostname`  `--dns` `--dns-search` and
   312  `--mac-address` is invalid in `host` netmode.
   313  
   314  Compared to the default `bridge` mode, the `host` mode gives *significantly*
   315  better networking performance since it uses the host's native networking stack
   316  whereas the bridge has to go through one level of virtualization through the
   317  docker daemon. It is recommended to run containers in this mode when their
   318  networking performance is critical, for example, a production Load Balancer
   319  or a High Performance Web Server.
   320  
   321  > **Note**: `--net="host"` gives the container full access to local system
   322  > services such as D-bus and is therefore considered insecure.
   323  
   324  #### Mode: container
   325  
   326  With the networking mode set to `container` a container will share the
   327  network stack of another container.  The other container's name must be
   328  provided in the format of `--net container:<name|id>`. Note that `--add-host`
   329  `--hostname` `--dns` `--dns-search` and `--mac-address` is invalid
   330  in `container` netmode, and `--publish` `--publish-all` `--expose` are also
   331  invalid in `container` netmode.
   332  
   333  Example running a Redis container with Redis binding to `localhost` then
   334  running the `redis-cli` command and connecting to the Redis server over the
   335  `localhost` interface.
   336  
   337      $ docker run -d --name redis example/redis --bind 127.0.0.1
   338      $ # use the redis container's network stack to access localhost
   339      $ docker run --rm -it --net container:redis example/redis-cli -h 127.0.0.1
   340  
   341  ### Managing /etc/hosts
   342  
   343  Your container will have lines in `/etc/hosts` which define the hostname of the
   344  container itself as well as `localhost` and a few other common things.  The
   345  `--add-host` flag can be used to add additional lines to `/etc/hosts`.
   346  
   347      $ docker run -it --add-host db-static:86.75.30.9 ubuntu cat /etc/hosts
   348      172.17.0.22     09d03f76bf2c
   349      fe00::0         ip6-localnet
   350      ff00::0         ip6-mcastprefix
   351      ff02::1         ip6-allnodes
   352      ff02::2         ip6-allrouters
   353      127.0.0.1       localhost
   354      ::1	            localhost ip6-localhost ip6-loopback
   355      86.75.30.9      db-static
   356  
   357  ## Restart policies (--restart)
   358  
   359  Using the `--restart` flag on Docker run you can specify a restart policy for
   360  how a container should or should not be restarted on exit.
   361  
   362  When a restart policy is active on a container, it will be shown as either `Up`
   363  or `Restarting` in [`docker ps`](/reference/commandline/cli/#ps). It can also be
   364  useful to use [`docker events`](/reference/commandline/cli/#events) to see the
   365  restart policy in effect.
   366  
   367  Docker supports the following restart policies:
   368  
   369  <table>
   370    <thead>
   371      <tr>
   372        <th>Policy</th>
   373        <th>Result</th>
   374      </tr>
   375    </thead>
   376    <tbody>
   377      <tr>
   378        <td><strong>no</strong></td>
   379        <td>
   380          Do not automatically restart the container when it exits. This is the
   381          default.
   382        </td>
   383      </tr>
   384      <tr>
   385        <td>
   386          <span style="white-space: nowrap">
   387            <strong>on-failure</strong>[:max-retries]
   388          </span>
   389        </td>
   390        <td>
   391          Restart only if the container exits with a non-zero exit status.
   392          Optionally, limit the number of restart retries the Docker
   393          daemon attempts.
   394        </td>
   395      </tr>
   396      <tr>
   397        <td><strong>always</strong></td>
   398        <td>
   399          Always restart the container regardless of the exit status.
   400          When you specify always, the Docker daemon will try to restart
   401          the container indefinitely.
   402        </td>
   403      </tr>
   404    </tbody>
   405  </table>
   406  
   407  An ever increasing delay (double the previous delay, starting at 100
   408  milliseconds) is added before each restart to prevent flooding the server.
   409  This means the daemon will wait for 100 ms, then 200 ms, 400, 800, 1600,
   410  and so on until either the `on-failure` limit is hit, or when you `docker stop`
   411  or `docker rm -f` the container.
   412  
   413  If a container is successfully restarted (the container is started and runs
   414  for at least 10 seconds), the delay is reset to its default value of 100 ms.
   415  
   416  You can specify the maximum amount of times Docker will try to restart the
   417  container when using the **on-failure** policy.  The default is that Docker
   418  will try forever to restart the container. The number of (attempted) restarts
   419  for a container can be obtained via [`docker inspect`](
   420  /reference/commandline/cli/#inspect). For example, to get the number of restarts
   421  for container "my-container";
   422  
   423      $ docker inspect -f "{{ .RestartCount }}" my-container
   424      # 2
   425  
   426  Or, to get the last time the container was (re)started;
   427  
   428      $ docker inspect -f "{{ .State.StartedAt }}" my-container
   429      # 2015-03-04T23:47:07.691840179Z
   430  
   431  You cannot set any restart policy in combination with
   432  ["clean up (--rm)"](#clean-up-rm). Setting both `--restart` and `--rm`
   433  results in an error.
   434  
   435  ### Examples
   436  
   437      $ docker run --restart=always redis
   438  
   439  This will run the `redis` container with a restart policy of **always**
   440  so that if the container exits, Docker will restart it.
   441  
   442      $ docker run --restart=on-failure:10 redis
   443  
   444  This will run the `redis` container with a restart policy of **on-failure**
   445  and a maximum restart count of 10.  If the `redis` container exits with a
   446  non-zero exit status more than 10 times in a row Docker will abort trying to
   447  restart the container. Providing a maximum restart limit is only valid for the
   448  **on-failure** policy.
   449  
   450  ## Clean up (--rm)
   451  
   452  By default a container's file system persists even after the container
   453  exits. This makes debugging a lot easier (since you can inspect the
   454  final state) and you retain all your data by default. But if you are
   455  running short-term **foreground** processes, these container file
   456  systems can really pile up. If instead you'd like Docker to
   457  **automatically clean up the container and remove the file system when
   458  the container exits**, you can add the `--rm` flag:
   459  
   460      --rm=false: Automatically remove the container when it exits (incompatible with -d)
   461  
   462  ## Security configuration
   463      --security-opt="label:user:USER"   : Set the label user for the container
   464      --security-opt="label:role:ROLE"   : Set the label role for the container
   465      --security-opt="label:type:TYPE"   : Set the label type for the container
   466      --security-opt="label:level:LEVEL" : Set the label level for the container
   467      --security-opt="label:disable"     : Turn off label confinement for the container
   468      --security-opt="apparmor:PROFILE"  : Set the apparmor profile to be applied
   469                                           to the container
   470  
   471  You can override the default labeling scheme for each container by specifying
   472  the `--security-opt` flag. For example, you can specify the MCS/MLS level, a
   473  requirement for MLS systems. Specifying the level in the following command
   474  allows you to share the same content between containers.
   475  
   476      $ docker run --security-opt label:level:s0:c100,c200 -i -t fedora bash
   477  
   478  An MLS example might be:
   479  
   480      $ docker run --security-opt label:level:TopSecret -i -t rhel7 bash
   481  
   482  To disable the security labeling for this container versus running with the
   483  `--permissive` flag, use the following command:
   484  
   485      $ docker run --security-opt label:disable -i -t fedora bash
   486  
   487  If you want a tighter security policy on the processes within a container,
   488  you can specify an alternate type for the container. You could run a container
   489  that is only allowed to listen on Apache ports by executing the following
   490  command:
   491  
   492      $ docker run --security-opt label:type:svirt_apache_t -i -t centos bash
   493  
   494  Note:
   495  
   496  You would have to write policy defining a `svirt_apache_t` type.
   497  
   498  ## Specifying custom cgroups
   499  
   500  Using the `--cgroup-parent` flag, you can pass a specific cgroup to run a
   501  container in. This allows you to create and manage cgroups on their own. You can
   502  define custom resources for those cgroups and put containers under a common
   503  parent group.
   504  
   505  ## Runtime constraints on resources
   506  
   507  The operator can also adjust the performance parameters of the
   508  container:
   509  
   510      -m, --memory="": Memory limit (format: <number><optional unit>, where unit = b, k, m or g)
   511      --memory-swap="": Total memory limit (memory + swap, format: <number><optional unit>, where unit = b, k, m or g)
   512      -c, --cpu-shares=0: CPU shares (relative weight)
   513      --cpu-period=0: Limit the CPU CFS (Completely Fair Scheduler) period
   514      --cpuset-cpus="": CPUs in which to allow execution (0-3, 0,1)
   515      --cpuset-mems="": Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.
   516      --cpu-quota=0: Limit the CPU CFS (Completely Fair Scheduler) quota
   517      --blkio-weight=0: Block IO weight (relative weight) accepts a weight value between 10 and 1000.
   518      --oom-kill-disable=true|false: Whether to disable OOM Killer for the container or not.
   519      --memory-swappiness="": Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100.
   520  
   521  ### Memory constraints
   522  
   523  We have four ways to set memory usage:
   524  
   525  <table>
   526    <thead>
   527      <tr>
   528        <th>Option</th>
   529        <th>Result</th>
   530      </tr>
   531    </thead>
   532    <tbody>
   533      <tr>
   534        <td class="no-wrap">
   535            <strong>memory=inf, memory-swap=inf</strong> (default)
   536        </td>
   537        <td>
   538          There is no memory limit for the container. The container can use
   539          as much memory as needed.
   540        </td>
   541      </tr>
   542      <tr>
   543        <td class="no-wrap"><strong>memory=L&lt;inf, memory-swap=inf</strong></td>
   544        <td>
   545          (specify memory and set memory-swap as <code>-1</code>) The container is
   546          not allowed to use more than L bytes of memory, but can use as much swap
   547          as is needed (if the host supports swap memory).
   548        </td>
   549      </tr>
   550      <tr>
   551        <td class="no-wrap"><strong>memory=L&lt;inf, memory-swap=2*L</strong></td>
   552        <td>
   553          (specify memory without memory-swap) The container is not allowed to
   554          use more than L bytes of memory, swap *plus* memory usage is double
   555          of that.
   556        </td>
   557      </tr>
   558      <tr>
   559        <td class="no-wrap">
   560            <strong>memory=L&lt;inf, memory-swap=S&lt;inf, L&lt;=S</strong>
   561        </td>
   562        <td>
   563          (specify both memory and memory-swap) The container is not allowed to
   564          use more than L bytes of memory, swap *plus* memory usage is limited
   565          by S.
   566        </td>
   567      </tr>
   568    </tbody>
   569  </table>
   570  
   571  Examples:
   572  
   573      $ docker run -ti ubuntu:14.04 /bin/bash
   574  
   575  We set nothing about memory, this means the processes in the container can use
   576  as much memory and swap memory as they need.
   577  
   578      $ docker run -ti -m 300M --memory-swap -1 ubuntu:14.04 /bin/bash
   579  
   580  We set memory limit and disabled swap memory limit, this means the processes in
   581  the container can use 300M memory and as much swap memory as they need (if the
   582  host supports swap memory).
   583  
   584      $ docker run -ti -m 300M ubuntu:14.04 /bin/bash
   585  
   586  We set memory limit only, this means the processes in the container can use
   587  300M memory and 300M swap memory, by default, the total virtual memory size
   588  (--memory-swap) will be set as double of memory, in this case, memory + swap
   589  would be 2*300M, so processes can use 300M swap memory as well.
   590  
   591      $ docker run -ti -m 300M --memory-swap 1G ubuntu:14.04 /bin/bash
   592  
   593  We set both memory and swap memory, so the processes in the container can use
   594  300M memory and 700M swap memory.
   595  
   596  By default, kernel kills processes in a container if an out-of-memory (OOM)
   597  error occurs. To change this behaviour, use the `--oom-kill-disable` option.
   598  Only disable the OOM killer on containers where you have also set the
   599  `-m/--memory` option. If the `-m` flag is not set, this can result in the host
   600  running out of memory and require killing the host's system processes to free
   601  memory.
   602  
   603  Examples:
   604  
   605  The following example limits the memory to 100M and disables the OOM killer for
   606  this container:
   607  
   608      $ docker run -ti -m 100M --oom-kill-disable ubuntu:14.04 /bin/bash
   609  
   610  The following example, illustrates a dangerous way to use the flag:
   611  
   612      $ docker run -ti --oom-kill-disable ubuntu:14.04 /bin/bash
   613  
   614  The container has unlimited memory which can cause the host to run out memory
   615  and require killing system processes to free memory.
   616  
   617  ### Swappiness constraint
   618  
   619  By default, a container's kernel can swap out a percentage of anonymous pages.
   620  To set this percentage for a container, specify a `--memory-swappiness` value
   621  between 0 and 100. A value of 0 turns off anonymous page swapping. A value of
   622  100 sets all anonymous pages as swappable. By default, if you are not using
   623  `--memory-swappiness`, memory swappiness value will be inherited from the parent.
   624  
   625  For example, you can set:
   626  
   627      $ docker run -ti --memory-swappiness=0 ubuntu:14.04 /bin/bash
   628  
   629  Setting the `--memory-swappiness` option is helpful when you want to retain the
   630  container's working set and to avoid swapping performance penalties.
   631  
   632  ### CPU share constraint
   633  
   634  By default, all containers get the same proportion of CPU cycles. This proportion
   635  can be modified by changing the container's CPU share weighting relative
   636  to the weighting of all other running containers.
   637  
   638  To modify the proportion from the default of 1024, use the `-c` or `--cpu-shares`
   639  flag to set the weighting to 2 or higher.
   640  
   641  The proportion will only apply when CPU-intensive processes are running.
   642  When tasks in one container are idle, other containers can use the
   643  left-over CPU time. The actual amount of CPU time will vary depending on
   644  the number of containers running on the system.
   645  
   646  For example, consider three containers, one has a cpu-share of 1024 and
   647  two others have a cpu-share setting of 512. When processes in all three
   648  containers attempt to use 100% of CPU, the first container would receive
   649  50% of the total CPU time. If you add a fourth container with a cpu-share
   650  of 1024, the first container only gets 33% of the CPU. The remaining containers
   651  receive 16.5%, 16.5% and 33% of the CPU.
   652  
   653  On a multi-core system, the shares of CPU time are distributed over all CPU
   654  cores. Even if a container is limited to less than 100% of CPU time, it can
   655  use 100% of each individual CPU core.
   656  
   657  For example, consider a system with more than three cores. If you start one
   658  container `{C0}` with `-c=512` running one process, and another container
   659  `{C1}` with `-c=1024` running two processes, this can result in the following
   660  division of CPU shares:
   661  
   662      PID    container	CPU	CPU share
   663      100    {C0}		0	100% of CPU0
   664      101    {C1}		1	100% of CPU1
   665      102    {C1}		2	100% of CPU2
   666  
   667  ### CPU period constraint
   668  
   669  The default CPU CFS (Completely Fair Scheduler) period is 100ms. We can use
   670  `--cpu-period` to set the period of CPUs to limit the container's CPU usage.
   671  And usually `--cpu-period` should work with `--cpu-quota`.
   672  
   673  Examples:
   674  
   675      $ docker run -ti --cpu-period=50000 --cpu-quota=25000 ubuntu:14.04 /bin/bash
   676  
   677  If there is 1 CPU, this means the container can get 50% CPU worth of run-time every 50ms.
   678  
   679  For more information, see the [CFS documentation on bandwidth limiting](https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt).
   680  
   681  ### Cpuset constraint
   682  
   683  We can set cpus in which to allow execution for containers.
   684  
   685  Examples:
   686  
   687      $ docker run -ti --cpuset-cpus="1,3" ubuntu:14.04 /bin/bash
   688  
   689  This means processes in container can be executed on cpu 1 and cpu 3.
   690  
   691      $ docker run -ti --cpuset-cpus="0-2" ubuntu:14.04 /bin/bash
   692  
   693  This means processes in container can be executed on cpu 0, cpu 1 and cpu 2.
   694  
   695  We can set mems in which to allow execution for containers. Only effective
   696  on NUMA systems.
   697  
   698  Examples:
   699  
   700      $ docker run -ti --cpuset-mems="1,3" ubuntu:14.04 /bin/bash
   701  
   702  This example restricts the processes in the container to only use memory from
   703  memory nodes 1 and 3.
   704  
   705      $ docker run -ti --cpuset-mems="0-2" ubuntu:14.04 /bin/bash
   706  
   707  This example restricts the processes in the container to only use memory from
   708  memory nodes 0, 1 and 2.
   709  
   710  ### CPU quota constraint
   711  
   712  The `--cpu-quota` flag limits the container's CPU usage. The default 0 value
   713  allows the container to take 100% of a CPU resource (1 CPU). The CFS (Completely Fair
   714  Scheduler) handles resource allocation for executing processes and is default
   715  Linux Scheduler used by the kernel. Set this value to 50000 to limit the container
   716  to 50% of a CPU resource. For multiple CPUs, adjust the `--cpu-quota` as necessary.
   717  For more information, see the [CFS documentation on bandwidth limiting](https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt).
   718  
   719  ### Block IO bandwidth (Blkio) constraint
   720  
   721  By default, all containers get the same proportion of block IO bandwidth
   722  (blkio). This proportion is 500. To modify this proportion, change the
   723  container's blkio weight relative to the weighting of all other running
   724  containers using the `--blkio-weight` flag.
   725  
   726  The `--blkio-weight` flag can set the weighting to a value between 10 to 1000.
   727  For example, the commands below create two containers with different blkio
   728  weight:
   729  
   730      $ docker run -ti --name c1 --blkio-weight 300 ubuntu:14.04 /bin/bash
   731      $ docker run -ti --name c2 --blkio-weight 600 ubuntu:14.04 /bin/bash
   732  
   733  If you do block IO in the two containers at the same time, by, for example:
   734  
   735      $ time dd if=/mnt/zerofile of=test.out bs=1M count=1024 oflag=direct
   736  
   737  You'll find that the proportion of time is the same as the proportion of blkio
   738  weights of the two containers.
   739  
   740  > **Note:** The blkio weight setting is only available for direct IO. Buffered IO
   741  > is not currently supported.
   742  
   743  ## Additional groups
   744      --group-add: Add Linux capabilities
   745  
   746  By default, the docker container process runs with the supplementary groups looked
   747  up for the specified user. If one wants to add more to that list of groups, then
   748  one can use this flag:
   749  
   750      $ docker run -ti --rm --group-add audio  --group-add dbus --group-add 777 busybox id
   751      uid=0(root) gid=0(root) groups=10(wheel),29(audio),81(dbus),777
   752  
   753  ## Runtime privilege, Linux capabilities, and LXC configuration
   754  
   755      --cap-add: Add Linux capabilities
   756      --cap-drop: Drop Linux capabilities
   757      --privileged=false: Give extended privileges to this container
   758      --device=[]: Allows you to run devices inside the container without the --privileged flag.
   759      --lxc-conf=[]: Add custom lxc options
   760  
   761  By default, Docker containers are "unprivileged" and cannot, for
   762  example, run a Docker daemon inside a Docker container. This is because
   763  by default a container is not allowed to access any devices, but a
   764  "privileged" container is given access to all devices (see [lxc-template.go](
   765  https://github.com/docker/docker/blob/master/daemon/execdriver/lxc/lxc_template.go)
   766  and documentation on [cgroups devices](
   767  https://www.kernel.org/doc/Documentation/cgroups/devices.txt)).
   768  
   769  When the operator executes `docker run --privileged`, Docker will enable
   770  to access to all devices on the host as well as set some configuration
   771  in AppArmor or SELinux to allow the container nearly all the same access to the
   772  host as processes running outside containers on the host. Additional
   773  information about running with `--privileged` is available on the
   774  [Docker Blog](http://blog.docker.com/2013/09/docker-can-now-run-within-docker/).
   775  
   776  If you want to limit access to a specific device or devices you can use
   777  the `--device` flag. It allows you to specify one or more devices that
   778  will be accessible within the container.
   779  
   780      $ docker run --device=/dev/snd:/dev/snd ...
   781  
   782  By default, the container will be able to `read`, `write`, and `mknod` these devices.
   783  This can be overridden using a third `:rwm` set of options to each `--device` flag:
   784  
   785      $ docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk  /dev/xvdc
   786  
   787      Command (m for help): q
   788      $ docker run --device=/dev/sda:/dev/xvdc:r --rm -it ubuntu fdisk  /dev/xvdc
   789      You will not be able to write the partition table.
   790  
   791      Command (m for help): q
   792  
   793      $ docker run --device=/dev/sda:/dev/xvdc:w --rm -it ubuntu fdisk  /dev/xvdc
   794          crash....
   795  
   796      $ docker run --device=/dev/sda:/dev/xvdc:m --rm -it ubuntu fdisk  /dev/xvdc
   797      fdisk: unable to open /dev/xvdc: Operation not permitted
   798  
   799  In addition to `--privileged`, the operator can have fine grain control over the
   800  capabilities using `--cap-add` and `--cap-drop`. By default, Docker has a default
   801  list of capabilities that are kept. The following table lists the Linux capability options which can be added or dropped.
   802  
   803  | Capability Key | Capability Description |
   804  | -------------- | ---------------------- |
   805  | SETPCAP | Modify process capabilities. |
   806  | SYS_MODULE| Load and unload kernel modules. |
   807  | SYS_RAWIO | Perform I/O port operations (iopl(2) and ioperm(2)). |
   808  | SYS_PACCT | Use acct(2), switch process accounting on or off. |
   809  | SYS_ADMIN | Perform a range of system administration operations. |
   810  | SYS_NICE | Raise process nice value (nice(2), setpriority(2)) and change the nice value for arbitrary processes. |
   811  | SYS_RESOURCE | Override resource Limits. |
   812  | SYS_TIME | Set system clock (settimeofday(2), stime(2), adjtimex(2)); set real-time (hardware) clock. |
   813  | SYS_TTY_CONFIG | Use vhangup(2); employ various privileged ioctl(2) operations on virtual terminals. |
   814  | MKNOD | Create special files using mknod(2). |
   815  | AUDIT_WRITE | Write records to kernel auditing log. |
   816  | AUDIT_CONTROL | Enable and disable kernel auditing; change auditing filter rules; retrieve auditing status and filtering rules. |
   817  | MAC_OVERRIDE | Allow MAC configuration or state changes. Implemented for the Smack LSM. |
   818  | MAC_ADMIN | Override Mandatory Access Control (MAC). Implemented for the Smack Linux Security Module (LSM). |
   819  | NET_ADMIN | Perform various network-related operations. |
   820  | SYSLOG | Perform privileged syslog(2) operations.  |
   821  | CHOWN | Make arbitrary changes to file UIDs and GIDs (see chown(2)). |
   822  | NET_RAW | Use RAW and PACKET sockets. |
   823  | DAC_OVERRIDE | Bypass file read, write, and execute permission checks. |
   824  | FOWNER | Bypass permission checks on operations that normally require the file system UID of the process to match the UID of the file. |
   825  | DAC_READ_SEARCH | Bypass file read permission checks and directory read and execute permission checks. |
   826  | FSETID | Don't clear set-user-ID and set-group-ID permission bits when a file is modified. |
   827  | KILL | Bypass permission checks for sending signals. |
   828  | SETGID | Make arbitrary manipulations of process GIDs and supplementary GID list. |
   829  | SETUID | Make arbitrary manipulations of process UIDs. |
   830  | LINUX_IMMUTABLE | Set the FS_APPEND_FL and FS_IMMUTABLE_FL i-node flags. |
   831  | NET_BIND_SERVICE  | Bind a socket to internet domain privileged ports (port numbers less than 1024). |
   832  | NET_BROADCAST |  Make socket broadcasts, and listen to multicasts. |
   833  | IPC_LOCK | Lock memory (mlock(2), mlockall(2), mmap(2), shmctl(2)). |
   834  | IPC_OWNER | Bypass permission checks for operations on System V IPC objects. |
   835  | SYS_CHROOT | Use chroot(2), change root directory. |
   836  | SYS_PTRACE | Trace arbitrary processes using ptrace(2). |
   837  | SYS_BOOT | Use reboot(2) and kexec_load(2), reboot and load a new kernel for later execution. |
   838  | LEASE | Establish leases on arbitrary files (see fcntl(2)). |
   839  | SETFCAP | Set file capabilities.|
   840  | WAKE_ALARM | Trigger something that will wake up the system. |
   841  | BLOCK_SUSPEND | Employ features that can block system suspend. |
   842  
   843  Further reference information is available on the [capabilities(7) - Linux man page](http://linux.die.net/man/7/capabilities)
   844  
   845  Both flags support the value `all`, so if the
   846  operator wants to have all capabilities but `MKNOD` they could use:
   847  
   848      $ docker run --cap-add=ALL --cap-drop=MKNOD ...
   849  
   850  For interacting with the network stack, instead of using `--privileged` they
   851  should use `--cap-add=NET_ADMIN` to modify the network interfaces.
   852  
   853      $ docker run -t -i --rm  ubuntu:14.04 ip link add dummy0 type dummy
   854      RTNETLINK answers: Operation not permitted
   855      $ docker run -t -i --rm --cap-add=NET_ADMIN ubuntu:14.04 ip link add dummy0 type dummy
   856  
   857  To mount a FUSE based filesystem, you need to combine both `--cap-add` and
   858  `--device`:
   859  
   860      $ docker run --rm -it --cap-add SYS_ADMIN sshfs sshfs sven@10.10.10.20:/home/sven /mnt
   861      fuse: failed to open /dev/fuse: Operation not permitted
   862      $ docker run --rm -it --device /dev/fuse sshfs sshfs sven@10.10.10.20:/home/sven /mnt
   863      fusermount: mount failed: Operation not permitted
   864      $ docker run --rm -it --cap-add SYS_ADMIN --device /dev/fuse sshfs
   865      # sshfs sven@10.10.10.20:/home/sven /mnt
   866      The authenticity of host '10.10.10.20 (10.10.10.20)' can't be established.
   867      ECDSA key fingerprint is 25:34:85:75:25:b0:17:46:05:19:04:93:b5:dd:5f:c6.
   868      Are you sure you want to continue connecting (yes/no)? yes
   869      sven@10.10.10.20's password:
   870      root@30aa0cfaf1b5:/# ls -la /mnt/src/docker
   871      total 1516
   872      drwxrwxr-x 1 1000 1000   4096 Dec  4 06:08 .
   873      drwxrwxr-x 1 1000 1000   4096 Dec  4 11:46 ..
   874      -rw-rw-r-- 1 1000 1000     16 Oct  8 00:09 .dockerignore
   875      -rwxrwxr-x 1 1000 1000    464 Oct  8 00:09 .drone.yml
   876      drwxrwxr-x 1 1000 1000   4096 Dec  4 06:11 .git
   877      -rw-rw-r-- 1 1000 1000    461 Dec  4 06:08 .gitignore
   878      ....
   879  
   880  
   881  If the Docker daemon was started using the `lxc` exec-driver
   882  (`docker -d --exec-driver=lxc`) then the operator can also specify LXC options
   883  using one or more `--lxc-conf` parameters. These can be new parameters or
   884  override existing parameters from the [lxc-template.go](
   885  https://github.com/docker/docker/blob/master/daemon/execdriver/lxc/lxc_template.go).
   886  Note that in the future, a given host's docker daemon may not use LXC, so this
   887  is an implementation-specific configuration meant for operators already
   888  familiar with using LXC directly.
   889  
   890  > **Note:**
   891  > If you use `--lxc-conf` to modify a container's configuration which is also
   892  > managed by the Docker daemon, then the Docker daemon will not know about this
   893  > modification, and you will need to manage any conflicts yourself. For example,
   894  > you can use `--lxc-conf` to set a container's IP address, but this will not be
   895  > reflected in the `/etc/hosts` file.
   896  
   897  # Logging drivers (--log-driver)
   898  
   899  The container can have a different logging driver than the Docker daemon. Use
   900  the `--log-driver=VALUE` with the `docker run` command to configure the
   901  container's logging driver. The following options are supported:
   902  
   903  | `none`      | Disables any logging for the container. `docker logs` won't be available with this driver.                                    |
   904  |-------------|-------------------------------------------------------------------------------------------------------------------------------|
   905  | `json-file` | Default logging driver for Docker. Writes JSON messages to file.  No logging options are supported for this driver.           |
   906  | `syslog`    | Syslog logging driver for Docker. Writes log messages to syslog.                                                              |
   907  | `journald`  | Journald logging driver for Docker. Writes log messages to `journald`.                                                        |
   908  | `gelf`      | Graylog Extended Log Format (GELF) logging driver for Docker. Writes log messages to a GELF endpoint likeGraylog or Logstash. |
   909  | `fluentd`   | Fluentd logging driver for Docker. Writes log messages to `fluentd` (forward input).                                          |
   910  
   911  	The `docker logs`command is available only for the `json-file` logging
   912  driver.  For detailed information on working with logging drivers, see
   913  [Configure a logging driver](reference/logging/).
   914  
   915  #### Logging driver: fluentd
   916  
   917  Fluentd logging driver for Docker. Writes log messages to fluentd (forward input). `docker logs`
   918  command is not available for this logging driver.
   919  
   920  Some options are supported by specifying `--log-opt` as many as needed, like `--log-opt fluentd-address=localhost:24224 --log-opt fluentd-tag=docker.{{.Name}}`.
   921  
   922   - `fluentd-address`: specify `host:port` to connect [localhost:24224]
   923   - `fluentd-tag`: specify tag for fluentd message, which interpret some markup, ex `{{.ID}}`, `{{.FullID}}` or `{{.Name}}` [docker.{{.ID}}]
   924  
   925  ## Overriding Dockerfile image defaults
   926  
   927  When a developer builds an image from a [*Dockerfile*](/reference/builder)
   928  or when she commits it, the developer can set a number of default parameters
   929  that take effect when the image starts up as a container.
   930  
   931  Four of the Dockerfile commands cannot be overridden at runtime: `FROM`,
   932  `MAINTAINER`, `RUN`, and `ADD`. Everything else has a corresponding override
   933  in `docker run`. We'll go through what the developer might have set in each
   934  Dockerfile instruction and how the operator can override that setting.
   935  
   936   - [CMD (Default Command or Options)](#cmd-default-command-or-options)
   937   - [ENTRYPOINT (Default Command to Execute at Runtime)](
   938      #entrypoint-default-command-to-execute-at-runtime)
   939   - [EXPOSE (Incoming Ports)](#expose-incoming-ports)
   940   - [ENV (Environment Variables)](#env-environment-variables)
   941   - [VOLUME (Shared Filesystems)](#volume-shared-filesystems)
   942   - [USER](#user)
   943   - [WORKDIR](#workdir)
   944  
   945  ## CMD (default command or options)
   946  
   947  Recall the optional `COMMAND` in the Docker
   948  commandline:
   949  
   950      $ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
   951  
   952  This command is optional because the person who created the `IMAGE` may
   953  have already provided a default `COMMAND` using the Dockerfile `CMD`
   954  instruction. As the operator (the person running a container from the
   955  image), you can override that `CMD` instruction just by specifying a new
   956  `COMMAND`.
   957  
   958  If the image also specifies an `ENTRYPOINT` then the `CMD` or `COMMAND`
   959  get appended as arguments to the `ENTRYPOINT`.
   960  
   961  ## ENTRYPOINT (default command to execute at runtime)
   962  
   963      --entrypoint="": Overwrite the default entrypoint set by the image
   964  
   965  The `ENTRYPOINT` of an image is similar to a `COMMAND` because it
   966  specifies what executable to run when the container starts, but it is
   967  (purposely) more difficult to override. The `ENTRYPOINT` gives a
   968  container its default nature or behavior, so that when you set an
   969  `ENTRYPOINT` you can run the container *as if it were that binary*,
   970  complete with default options, and you can pass in more options via the
   971  `COMMAND`. But, sometimes an operator may want to run something else
   972  inside the container, so you can override the default `ENTRYPOINT` at
   973  runtime by using a string to specify the new `ENTRYPOINT`. Here is an
   974  example of how to run a shell in a container that has been set up to
   975  automatically run something else (like `/usr/bin/redis-server`):
   976  
   977      $ docker run -i -t --entrypoint /bin/bash example/redis
   978  
   979  or two examples of how to pass more parameters to that ENTRYPOINT:
   980  
   981      $ docker run -i -t --entrypoint /bin/bash example/redis -c ls -l
   982      $ docker run -i -t --entrypoint /usr/bin/redis-cli example/redis --help
   983  
   984  ## EXPOSE (incoming ports)
   985  
   986  The Dockerfile doesn't give much control over networking, only providing
   987  the `EXPOSE` instruction to give a hint to the operator about what
   988  incoming ports might provide services. The following options work with
   989  or override the Dockerfile's exposed defaults:
   990  
   991      --expose=[]: Expose a port or a range of ports from the container
   992                  without publishing it to your host
   993      -P=false   : Publish all exposed ports to the host interfaces
   994      -p=[]      : Publish a container᾿s port or a range of ports to the host
   995                     format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
   996                     Both hostPort and containerPort can be specified as a range of ports.
   997                     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`)
   998                     (use 'docker port' to see the actual mapping)
   999      --link=""  : Add link to another container (<name or id>:alias or <name or id>)
  1000  
  1001  As mentioned previously, `EXPOSE` (and `--expose`) makes ports available
  1002  **in** a container for incoming connections. The port number on the
  1003  inside of the container (where the service listens) does not need to be
  1004  the same number as the port exposed on the outside of the container
  1005  (where clients connect), so inside the container you might have an HTTP
  1006  service listening on port 80 (and so you `EXPOSE 80` in the Dockerfile),
  1007  but outside the container the port might be 42800.
  1008  
  1009  To help a new client container reach the server container's internal
  1010  port operator `--expose`'d by the operator or `EXPOSE`'d by the
  1011  developer, the operator has three choices: start the server container
  1012  with `-P` or `-p,` or start the client container with `--link`.
  1013  
  1014  If the operator uses `-P` or `-p` then Docker will make the exposed port
  1015  accessible on the host and the ports will be available to any client that can
  1016  reach the host. When using `-P`, Docker will bind the exposed port to a random
  1017  port on the host within an *ephemeral port range* defined by
  1018  `/proc/sys/net/ipv4/ip_local_port_range`. To find the mapping between the host
  1019  ports and the exposed ports, use `docker port`.
  1020  
  1021  If the operator uses `--link` when starting the new client container,
  1022  then the client container can access the exposed port via a private
  1023  networking interface.  Docker will set some environment variables in the
  1024  client container to help indicate which interface and port to use.
  1025  
  1026  ## ENV (environment variables)
  1027  
  1028  When a new container is created, Docker will set the following environment
  1029  variables automatically:
  1030  
  1031  <table>
  1032   <tr>
  1033    <th>Variable</th>
  1034    <th>Value</th>
  1035   </tr>
  1036   <tr>
  1037    <td><code>HOME</code></td>
  1038    <td>
  1039      Set based on the value of <code>USER</code>
  1040    </td>
  1041   </tr>
  1042   <tr>
  1043    <td><code>HOSTNAME</code></td>
  1044    <td>
  1045      The hostname associated with the container
  1046    </td>
  1047   </tr>
  1048   <tr>
  1049    <td><code>PATH</code></td>
  1050    <td>
  1051      Includes popular directories, such as :<br>
  1052      <code>/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin</code>
  1053    </td>
  1054   <tr>
  1055    <td><code>TERM</code></td>
  1056    <td><code>xterm</code> if the container is allocated a pseudo-TTY</td>
  1057   </tr>
  1058  </table>
  1059  
  1060  The container may also include environment variables defined
  1061  as a result of the container being linked with another container. See
  1062  the [*Container Links*](/userguide/dockerlinks/#container-linking)
  1063  section for more details.
  1064  
  1065  Additionally, the operator can **set any environment variable** in the
  1066  container by using one or more `-e` flags, even overriding those mentioned
  1067  above, or already defined by the developer with a Dockerfile `ENV`:
  1068  
  1069      $ docker run -e "deep=purple" --rm ubuntu /bin/bash -c export
  1070      declare -x HOME="/"
  1071      declare -x HOSTNAME="85bc26a0e200"
  1072      declare -x OLDPWD
  1073      declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  1074      declare -x PWD="/"
  1075      declare -x SHLVL="1"
  1076      declare -x container="lxc"
  1077      declare -x deep="purple"
  1078  
  1079  Similarly the operator can set the **hostname** with `-h`.
  1080  
  1081  `--link <name or id>:alias` also sets environment variables, using the *alias* string to
  1082  define environment variables within the container that give the IP and PORT
  1083  information for connecting to the service container. Let's imagine we have a
  1084  container running Redis:
  1085  
  1086      # Start the service container, named redis-name
  1087      $ docker run -d --name redis-name dockerfiles/redis
  1088      4241164edf6f5aca5b0e9e4c9eccd899b0b8080c64c0cd26efe02166c73208f3
  1089  
  1090      # The redis-name container exposed port 6379
  1091      $ docker ps
  1092      CONTAINER ID        IMAGE                        COMMAND                CREATED             STATUS              PORTS               NAMES
  1093      4241164edf6f        $ dockerfiles/redis:latest   /redis-stable/src/re   5 seconds ago       Up 4 seconds        6379/tcp            redis-name
  1094  
  1095      # Note that there are no public ports exposed since we didn᾿t use -p or -P
  1096      $ docker port 4241164edf6f 6379
  1097      2014/01/25 00:55:38 Error: No public port '6379' published for 4241164edf6f
  1098  
  1099  Yet we can get information about the Redis container's exposed ports
  1100  with `--link`. Choose an alias that will form a
  1101  valid environment variable!
  1102  
  1103      $ docker run --rm --link redis-name:redis_alias --entrypoint /bin/bash dockerfiles/redis -c export
  1104      declare -x HOME="/"
  1105      declare -x HOSTNAME="acda7f7b1cdc"
  1106      declare -x OLDPWD
  1107      declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  1108      declare -x PWD="/"
  1109      declare -x REDIS_ALIAS_NAME="/distracted_wright/redis"
  1110      declare -x REDIS_ALIAS_PORT="tcp://172.17.0.32:6379"
  1111      declare -x REDIS_ALIAS_PORT_6379_TCP="tcp://172.17.0.32:6379"
  1112      declare -x REDIS_ALIAS_PORT_6379_TCP_ADDR="172.17.0.32"
  1113      declare -x REDIS_ALIAS_PORT_6379_TCP_PORT="6379"
  1114      declare -x REDIS_ALIAS_PORT_6379_TCP_PROTO="tcp"
  1115      declare -x SHLVL="1"
  1116      declare -x container="lxc"
  1117  
  1118  And we can use that information to connect from another container as a client:
  1119  
  1120      $ docker run -i -t --rm --link redis-name:redis_alias --entrypoint /bin/bash dockerfiles/redis -c '/redis-stable/src/redis-cli -h $REDIS_ALIAS_PORT_6379_TCP_ADDR -p $REDIS_ALIAS_PORT_6379_TCP_PORT'
  1121      172.17.0.32:6379>
  1122  
  1123  Docker will also map the private IP address to the alias of a linked
  1124  container by inserting an entry into `/etc/hosts`.  You can use this
  1125  mechanism to communicate with a linked container by its alias:
  1126  
  1127      $ docker run -d --name servicename busybox sleep 30
  1128      $ docker run -i -t --link servicename:servicealias busybox ping -c 1 servicealias
  1129  
  1130  If you restart the source container (`servicename` in this case), the recipient
  1131  container's `/etc/hosts` entry will be automatically updated.
  1132  
  1133  > **Note**:
  1134  > Unlike host entries in the `/etc/hosts` file, IP addresses stored in the
  1135  > environment variables are not automatically updated if the source container is
  1136  > restarted. We recommend using the host entries in `/etc/hosts` to resolve the
  1137  > IP address of linked containers.
  1138  
  1139  ## VOLUME (shared filesystems)
  1140  
  1141      -v=[]: Create a bind mount with: [host-dir:]container-dir[:rw|ro].
  1142             If 'host-dir' is missing, then docker creates a new volume.
  1143  		   If neither 'rw' or 'ro' is specified then the volume is mounted
  1144  		   in read-write mode.
  1145      --volumes-from="": Mount all volumes from the given container(s)
  1146  
  1147  The volumes commands are complex enough to have their own documentation
  1148  in section [*Managing data in
  1149  containers*](/userguide/dockervolumes). A developer can define
  1150  one or more `VOLUME`'s associated with an image, but only the operator
  1151  can give access from one container to another (or from a container to a
  1152  volume mounted on the host).
  1153  
  1154  ## USER
  1155  
  1156  The default user within a container is `root` (id = 0), but if the
  1157  developer created additional users, those are accessible too. The
  1158  developer can set a default user to run the first process with the
  1159  Dockerfile `USER` instruction, but the operator can override it:
  1160  
  1161      -u="": Username or UID
  1162  
  1163  > **Note:** if you pass numeric uid, it must be in range 0-2147483647.
  1164  
  1165  ## WORKDIR
  1166  
  1167  The default working directory for running binaries within a container is the
  1168  root directory (`/`), but the developer can set a different default with the
  1169  Dockerfile `WORKDIR` command. The operator can override this with:
  1170  
  1171      -w="": Working directory inside the container