summaryrefslogtreecommitdiff
path: root/devdocs/docker/engine%2Freference%2Frun%2Findex.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/docker/engine%2Freference%2Frun%2Findex.html')
-rw-r--r--devdocs/docker/engine%2Freference%2Frun%2Findex.html333
1 files changed, 333 insertions, 0 deletions
diff --git a/devdocs/docker/engine%2Freference%2Frun%2Findex.html b/devdocs/docker/engine%2Freference%2Frun%2Findex.html
new file mode 100644
index 00000000..80bd9cc3
--- /dev/null
+++ b/devdocs/docker/engine%2Freference%2Frun%2Findex.html
@@ -0,0 +1,333 @@
+ <h1 id="docker-run-reference">Docker run reference</h1> <p>Docker runs processes in isolated containers. A container is a process which runs on a host. The host may be local or remote. When an operator executes <code class="language-plaintext highlighter-rouge">docker run</code>, the container process that runs is isolated in that it has its own file system, its own networking, and its own isolated process tree separate from the host.</p> <p>This page details how to use the <code class="language-plaintext highlighter-rouge">docker run</code> command to define the container’s resources at runtime.</p> <h2 id="general-form">General form</h2> <p>The basic <code class="language-plaintext highlighter-rouge">docker run</code> command takes this form:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
+</pre></div> <p>The <code class="language-plaintext highlighter-rouge">docker run</code> command must specify an <a href="https://docs.docker.com/glossary/#image"><em>IMAGE</em></a> to derive the container from. An image developer can define image defaults related to:</p> <ul> <li>detached or foreground running</li> <li>container identification</li> <li>network settings</li> <li>runtime constraints on CPU and memory</li> </ul> <p>With the <code class="language-plaintext highlighter-rouge">docker run [OPTIONS]</code> an operator can add to or override the image defaults set by a developer. And, additionally, operators can override nearly all the defaults set by the Docker runtime itself. The operator’s ability to override image and Docker runtime defaults is why <a href="../commandline/run/index"><em>run</em></a> has more options than any other <code class="language-plaintext highlighter-rouge">docker</code> command.</p> <p>To learn how to interpret the types of <code class="language-plaintext highlighter-rouge">[OPTIONS]</code>, see <a href="../commandline/cli/index#option-types"><em>Option types</em></a>.</p> <blockquote> <p><strong>Note</strong></p> <p>Depending on your Docker system configuration, you may be required to preface the <code class="language-plaintext highlighter-rouge">docker run</code> command with <code class="language-plaintext highlighter-rouge">sudo</code>. To avoid having to use <code class="language-plaintext highlighter-rouge">sudo</code> with the <code class="language-plaintext highlighter-rouge">docker</code> command, your system administrator can create a Unix group called <code class="language-plaintext highlighter-rouge">docker</code> and add users to it. For more information about this configuration, refer to the Docker installation documentation for your operating system.</p> </blockquote> <h2 id="operator-exclusive-options">Operator exclusive options</h2> <p>Only the operator (the person executing <code class="language-plaintext highlighter-rouge">docker run</code>) can set the following options.</p> <ul> <li>
+<a href="#detached-vs-foreground">Detached vs foreground</a> <ul> <li><a href="#detached--d">Detached (-d)</a></li> <li><a href="#foreground">Foreground</a></li> </ul> </li> <li>
+<a href="#container-identification">Container identification</a> <ul> <li><a href="#name---name">Name (--name)</a></li> <li><a href="#pid-equivalent">PID equivalent</a></li> </ul> </li> <li><a href="#ipc-settings---ipc">IPC settings (--ipc)</a></li> <li><a href="#network-settings">Network settings</a></li> <li><a href="#restart-policies---restart">Restart policies (--restart)</a></li> <li><a href="#clean-up---rm">Clean up (--rm)</a></li> <li><a href="#runtime-constraints-on-resources">Runtime constraints on resources</a></li> <li><a href="#runtime-privilege-and-linux-capabilities">Runtime privilege and Linux capabilities</a></li> </ul> <h2 id="detached-vs-foreground">Detached vs foreground</h2> <p>When starting a Docker container, you must first decide if you want to run the container in the background in a “detached” mode or in the default foreground mode:</p> <div class="highlight"><pre class="highlight" data-language="">-d=false: Detached mode: Run container in the background, print new container id
+</pre></div> <h3 id="detached--d">Detached (-d)</h3> <p>To start a container in detached mode, you use <code class="language-plaintext highlighter-rouge">-d=true</code> or just <code class="language-plaintext highlighter-rouge">-d</code> option. By design, containers started in detached mode exit when the root process used to run the container exits, unless you also specify the <code class="language-plaintext highlighter-rouge">--rm</code> option. If you use <code class="language-plaintext highlighter-rouge">-d</code> with <code class="language-plaintext highlighter-rouge">--rm</code>, the container is removed when it exits <strong>or</strong> when the daemon exits, whichever happens first.</p> <p>Do not pass a <code class="language-plaintext highlighter-rouge">service x start</code> command to a detached container. For example, this command attempts to start the <code class="language-plaintext highlighter-rouge">nginx</code> service.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -d -p 80:80 my_image service nginx start
+</pre></div> <p>This succeeds in starting the <code class="language-plaintext highlighter-rouge">nginx</code> service inside the container. However, it fails the detached container paradigm in that, the root process (<code class="language-plaintext highlighter-rouge">service nginx start</code>) returns and the detached container stops as designed. As a result, the <code class="language-plaintext highlighter-rouge">nginx</code> service is started but could not be used. Instead, to start a process such as the <code class="language-plaintext highlighter-rouge">nginx</code> web server do the following:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -d -p 80:80 my_image nginx -g 'daemon off;'
+</pre></div> <p>To do input/output with a detached container use network connections or shared volumes. These are required because the container is no longer listening to the command line where <code class="language-plaintext highlighter-rouge">docker run</code> was run.</p> <p>To reattach to a detached container, use <code class="language-plaintext highlighter-rouge">docker</code> <a href="../commandline/attach/index"><em>attach</em></a> command.</p> <h3 id="foreground">Foreground</h3> <p>In foreground mode (the default when <code class="language-plaintext highlighter-rouge">-d</code> is not specified), <code class="language-plaintext highlighter-rouge">docker run</code> can start the process in the container and attach the console to the process’s standard input, output, and standard error. It can even pretend to be a TTY (this is what most command line executables expect) and pass along signals. All of that is configurable:</p> <div class="highlight"><pre class="highlight" data-language="">-a=[] : Attach to `STDIN`, `STDOUT` and/or `STDERR`
+-t : Allocate a pseudo-tty
+--sig-proxy=true: Proxy all received signals to the process (non-TTY mode only)
+-i : Keep STDIN open even if not attached
+</pre></div> <p>If you do not specify <code class="language-plaintext highlighter-rouge">-a</code> then Docker will <a href="https://github.com/docker/docker/blob/4118e0c9eebda2412a09ae66e90c34b85fae3275/runconfig/opts/parse.go#L267">attach to both stdout and stderr </a>. You can specify to which of the three standard streams (<code class="language-plaintext highlighter-rouge">STDIN</code>, <code class="language-plaintext highlighter-rouge">STDOUT</code>, <code class="language-plaintext highlighter-rouge">STDERR</code>) you’d like to connect instead, as in:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -a stdin -a stdout -i -t ubuntu /bin/bash
+</pre></div> <p>For interactive processes (like a shell), you must use <code class="language-plaintext highlighter-rouge">-i -t</code> together in order to allocate a tty for the container process. <code class="language-plaintext highlighter-rouge">-i -t</code> is often written <code class="language-plaintext highlighter-rouge">-it</code> as you’ll see in later examples. Specifying <code class="language-plaintext highlighter-rouge">-t</code> is forbidden when the client is receiving its standard input from a pipe, as in:</p> <div class="highlight"><pre class="highlight" data-language="">$ echo test | docker run -i busybox cat
+</pre></div> <blockquote> <p><strong>Note</strong></p> <p>A process running as PID 1 inside a container is treated specially by Linux: it ignores any signal with the default action. As a result, the process will not terminate on <code class="language-plaintext highlighter-rouge">SIGINT</code> or <code class="language-plaintext highlighter-rouge">SIGTERM</code> unless it is coded to do so.</p> </blockquote> <h2 id="container-identification">Container identification</h2> <h3 id="name---name">Name (--name)</h3> <p>The operator can identify a container in three ways:</p> <table> <thead> <tr> <th style="text-align: left">Identifier type</th> <th style="text-align: left">Example value</th> </tr> </thead> <tbody> <tr> <td style="text-align: left">UUID long identifier</td> <td style="text-align: left">“f78375b1c487e03c9438c729345e54db9d20cfa2ac1fc3494b6eb60872e74778”</td> </tr> <tr> <td style="text-align: left">UUID short identifier</td> <td style="text-align: left">“f78375b1c487”</td> </tr> <tr> <td style="text-align: left">Name</td> <td style="text-align: left">“evil_ptolemy”</td> </tr> </tbody> </table> <p>The UUID identifiers come from the Docker daemon. If you do not assign a container name with the <code class="language-plaintext highlighter-rouge">--name</code> option, then the daemon generates a random string name for you. Defining a <code class="language-plaintext highlighter-rouge">name</code> can be a handy way to add meaning to a container. If you specify a <code class="language-plaintext highlighter-rouge">name</code>, you can use it when referencing the container within a Docker network. This works for both background and foreground Docker containers.</p> <blockquote> <p><strong>Note</strong></p> <p>Containers on the default bridge network must be linked to communicate by name.</p> </blockquote> <h3 id="pid-equivalent">PID equivalent</h3> <p>Finally, to help with automation, you can have Docker write the container ID out to a file of your choosing. This is similar to how some programs might write out their process ID to a file (you’ve seen them as PID files):</p> <div class="highlight"><pre class="highlight" data-language="">--cidfile="": Write the container ID to the file
+</pre></div> <h3 id="imagetag">Image[:tag]</h3> <p>While not strictly a means of identifying a container, you can specify a version of an image you’d like to run the container with by adding <code class="language-plaintext highlighter-rouge">image[:tag]</code> to the command. For example, <code class="language-plaintext highlighter-rouge">docker run ubuntu:14.04</code>.</p> <h3 id="imagedigest">Image[@digest]</h3> <p>Images using the v2 or later image format have a content-addressable identifier called a digest. As long as the input used to generate the image is unchanged, the digest value is predictable and referenceable.</p> <p>The following example runs a container from the <code class="language-plaintext highlighter-rouge">alpine</code> image with the <code class="language-plaintext highlighter-rouge">sha256:9cacb71397b640eca97488cf08582ae4e4068513101088e9f96c9814bfda95e0</code> digest:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run alpine@sha256:9cacb71397b640eca97488cf08582ae4e4068513101088e9f96c9814bfda95e0 date
+</pre></div> <h2 id="pid-settings---pid">PID settings (--pid)</h2> <div class="highlight"><pre class="highlight" data-language="">--pid="" : Set the PID (Process) Namespace mode for the container,
+ 'container:&lt;name|id&gt;': joins another container's PID namespace
+ 'host': use the host's PID namespace inside the container
+</pre></div> <p>By default, all containers have the PID namespace enabled.</p> <p>PID namespace provides separation of processes. The PID Namespace removes the view of the system processes, and allows process ids to be reused including pid 1.</p> <p>In certain cases you want your container to share the host’s process namespace, basically allowing processes within the container to see all of the processes on the system. For example, you could build a container with debugging tools like <code class="language-plaintext highlighter-rouge">strace</code> or <code class="language-plaintext highlighter-rouge">gdb</code>, but want to use these tools when debugging processes within the container.</p> <h3 id="example-run-htop-inside-a-container">Example: run htop inside a container</h3> <p>Create this Dockerfile:</p> <div class="highlight"><pre class="highlight" data-language="">FROM alpine:latest
+RUN apk add --update htop &amp;&amp; rm -rf /var/cache/apk/*
+CMD ["htop"]
+</pre></div> <p>Build the Dockerfile and tag the image as <code class="language-plaintext highlighter-rouge">myhtop</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker build -t myhtop .
+</pre></div> <p>Use the following command to run <code class="language-plaintext highlighter-rouge">htop</code> inside a container:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --rm --pid=host myhtop
+</pre></div> <p>Joining another container’s pid namespace can be used for debugging that container.</p> <h3 id="example">Example</h3> <p>Start a container running a redis server:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --name my-redis -d redis
+</pre></div> <p>Debug the redis container by running another container that has strace in it:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --pid=container:my-redis my_strace_docker_image bash
+$ strace -p 1
+</pre></div> <h2 id="uts-settings---uts">UTS settings (--uts)</h2> <div class="highlight"><pre class="highlight" data-language="">--uts="" : Set the UTS namespace mode for the container,
+ 'host': use the host's UTS namespace inside the container
+</pre></div> <p>The UTS namespace is for setting the hostname and the domain that is visible to running processes in that namespace. By default, all containers, including those with <code class="language-plaintext highlighter-rouge">--network=host</code>, have their own UTS namespace. The <code class="language-plaintext highlighter-rouge">host</code> setting will result in the container using the same UTS namespace as the host. Note that <code class="language-plaintext highlighter-rouge">--hostname</code> and <code class="language-plaintext highlighter-rouge">--domainname</code> are invalid in <code class="language-plaintext highlighter-rouge">host</code> UTS mode.</p> <p>You may wish to share the UTS namespace with the host if you would like the hostname of the container to change as the hostname of the host changes. A more advanced use case would be changing the host’s hostname from a container.</p> <h2 id="ipc-settings---ipc">IPC settings (--ipc)</h2> <div class="highlight"><pre class="highlight" data-language="">--ipc="MODE" : Set the IPC mode for the container
+</pre></div> <p>The following values are accepted:</p> <table> <thead> <tr> <th style="text-align: left">Value</th> <th style="text-align: left">Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left">””</td> <td style="text-align: left">Use daemon’s default.</td> </tr> <tr> <td style="text-align: left">“none”</td> <td style="text-align: left">Own private IPC namespace, with /dev/shm not mounted.</td> </tr> <tr> <td style="text-align: left">“private”</td> <td style="text-align: left">Own private IPC namespace.</td> </tr> <tr> <td style="text-align: left">“shareable”</td> <td style="text-align: left">Own private IPC namespace, with a possibility to share it with other containers.</td> </tr> <tr> <td style="text-align: left">“container: &lt;_name-or-ID_&gt;" </td> <td style="text-align: left">Join another (“shareable”) container’s IPC namespace.</td> </tr> <tr> <td style="text-align: left">“host”</td> <td style="text-align: left">Use the host system’s IPC namespace.</td> </tr> </tbody> </table> <p>If not specified, daemon default is used, which can either be <code class="language-plaintext highlighter-rouge">"private"</code> or <code class="language-plaintext highlighter-rouge">"shareable"</code>, depending on the daemon version and configuration.</p> <p>IPC (POSIX/SysV IPC) namespace provides separation of named shared memory segments, semaphores and message queues.</p> <p>Shared memory segments are used to accelerate inter-process communication at memory speed, rather than through pipes or through the network stack. Shared memory is commonly used by databases and custom-built (typically C/OpenMPI, C++/using boost libraries) high performance applications for scientific computing and financial services industries. If these types of applications are broken into multiple containers, you might need to share the IPC mechanisms of the containers, using <code class="language-plaintext highlighter-rouge">"shareable"</code> mode for the main (i.e. “donor”) container, and <code class="language-plaintext highlighter-rouge">"container:&lt;donor-name-or-ID&gt;"</code> for other containers.</p> <h2 id="network-settings">Network settings</h2> <div class="highlight"><pre class="highlight" data-language="">--dns=[] : Set custom dns servers for the container
+--network="bridge" : Connect a container to a network
+ 'bridge': create a network stack on the default Docker bridge
+ 'none': no networking
+ 'container:&lt;name|id&gt;': reuse another container's network stack
+ 'host': use the Docker host network stack
+ '&lt;network-name&gt;|&lt;network-id&gt;': connect to a user-defined network
+--network-alias=[] : Add network-scoped alias for the container
+--add-host="" : Add a line to /etc/hosts (host:IP)
+--mac-address="" : Sets the container's Ethernet device's MAC address
+--ip="" : Sets the container's Ethernet device's IPv4 address
+--ip6="" : Sets the container's Ethernet device's IPv6 address
+--link-local-ip=[] : Sets one or more container's Ethernet device's link local IPv4/IPv6 addresses
+</pre></div> <p>By default, all containers have networking enabled and they can make any outgoing connections. The operator can completely disable networking with <code class="language-plaintext highlighter-rouge">docker run --network none</code> which disables all incoming and outgoing networking. In cases like this, you would perform I/O through files or <code class="language-plaintext highlighter-rouge">STDIN</code> and <code class="language-plaintext highlighter-rouge">STDOUT</code> only.</p> <p>Publishing ports and linking to other containers only works with the default (bridge). The linking feature is a legacy feature. You should always prefer using Docker network drivers over linking.</p> <p>Your container will use the same DNS servers as the host by default, but you can override this with <code class="language-plaintext highlighter-rouge">--dns</code>.</p> <p>By default, the MAC address is generated using the IP address allocated to the container. You can set the container’s MAC address explicitly by providing a MAC address via the <code class="language-plaintext highlighter-rouge">--mac-address</code> parameter (format:<code class="language-plaintext highlighter-rouge">12:34:56:78:9a:bc</code>).Be aware that Docker does not check if manually specified MAC addresses are unique.</p> <p>Supported networks :</p> <table> <thead> <tr> <th class="no-wrap">Network</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td class="no-wrap"><strong>none</strong></td> <td>No networking in the container.</td> </tr> <tr> <td class="no-wrap">
+<strong>bridge</strong> (default)</td> <td>Connect the container to the bridge via veth interfaces.</td> </tr> <tr> <td class="no-wrap"><strong>host</strong></td> <td>Use the host's network stack inside the container.</td> </tr> <tr> <td class="no-wrap">
+<strong>container</strong>:&lt;name|id&gt;</td> <td>Use the network stack of another container, specified via its <em>name</em> or <em>id</em>.</td> </tr> <tr> <td class="no-wrap"><strong>NETWORK</strong></td> <td>Connects the container to a user created network (using <code class="language-plaintext highlighter-rouge">docker network create</code> command)</td> </tr> </tbody> </table> <h4 id="network-none">Network: none</h4> <p>With the network is <code class="language-plaintext highlighter-rouge">none</code> a container will not have access to any external routes. The container will still have a <code class="language-plaintext highlighter-rouge">loopback</code> interface enabled in the container but it does not have any routes to external traffic.</p> <h4 id="network-bridge">Network: bridge</h4> <p>With the network set to <code class="language-plaintext highlighter-rouge">bridge</code> a container will use docker’s default networking setup. A bridge is setup on the host, commonly named <code class="language-plaintext highlighter-rouge">docker0</code>, and a pair of <code class="language-plaintext highlighter-rouge">veth</code> interfaces will be created for the container. One side of the <code class="language-plaintext highlighter-rouge">veth</code> pair will remain on the host attached to the bridge while the other side of the pair will be placed inside the container’s namespaces in addition to the <code class="language-plaintext highlighter-rouge">loopback</code> interface. An IP address will be allocated for containers on the bridge’s network and traffic will be routed though this bridge to the container.</p> <p>Containers can communicate via their IP addresses by default. To communicate by name, they must be linked.</p> <h4 id="network-host">Network: host</h4> <p>With the network set to <code class="language-plaintext highlighter-rouge">host</code> a container will share the host’s network stack and all interfaces from the host will be available to the container. The container’s hostname will match the hostname on the host system. Note that <code class="language-plaintext highlighter-rouge">--mac-address</code> is invalid in <code class="language-plaintext highlighter-rouge">host</code> netmode. Even in <code class="language-plaintext highlighter-rouge">host</code> network mode a container has its own UTS namespace by default. As such <code class="language-plaintext highlighter-rouge">--hostname</code> and <code class="language-plaintext highlighter-rouge">--domainname</code> are allowed in <code class="language-plaintext highlighter-rouge">host</code> network mode and will only change the hostname and domain name inside the container. Similar to <code class="language-plaintext highlighter-rouge">--hostname</code>, the <code class="language-plaintext highlighter-rouge">--add-host</code>, <code class="language-plaintext highlighter-rouge">--dns</code>, <code class="language-plaintext highlighter-rouge">--dns-search</code>, and <code class="language-plaintext highlighter-rouge">--dns-option</code> options can be used in <code class="language-plaintext highlighter-rouge">host</code> network mode. These options update <code class="language-plaintext highlighter-rouge">/etc/hosts</code> or <code class="language-plaintext highlighter-rouge">/etc/resolv.conf</code> inside the container. No change are made to <code class="language-plaintext highlighter-rouge">/etc/hosts</code> and <code class="language-plaintext highlighter-rouge">/etc/resolv.conf</code> on the host.</p> <p>Compared to the default <code class="language-plaintext highlighter-rouge">bridge</code> mode, the <code class="language-plaintext highlighter-rouge">host</code> mode gives <em>significantly</em> better networking performance since it uses the host’s native networking stack whereas the bridge has to go through one level of virtualization through the docker daemon. It is recommended to run containers in this mode when their networking performance is critical, for example, a production Load Balancer or a High Performance Web Server.</p> <blockquote> <p><strong>Note</strong></p> <p><code class="language-plaintext highlighter-rouge">--network="host"</code> gives the container full access to local system services such as D-bus and is therefore considered insecure.</p> </blockquote> <h4 id="network-container">Network: container</h4> <p>With the network set to <code class="language-plaintext highlighter-rouge">container</code> a container will share the network stack of another container. The other container’s name must be provided in the format of <code class="language-plaintext highlighter-rouge">--network container:&lt;name|id&gt;</code>. Note that <code class="language-plaintext highlighter-rouge">--add-host</code> <code class="language-plaintext highlighter-rouge">--hostname</code> <code class="language-plaintext highlighter-rouge">--dns</code> <code class="language-plaintext highlighter-rouge">--dns-search</code> <code class="language-plaintext highlighter-rouge">--dns-option</code> and <code class="language-plaintext highlighter-rouge">--mac-address</code> are invalid in <code class="language-plaintext highlighter-rouge">container</code> netmode, and <code class="language-plaintext highlighter-rouge">--publish</code> <code class="language-plaintext highlighter-rouge">--publish-all</code> <code class="language-plaintext highlighter-rouge">--expose</code> are also invalid in <code class="language-plaintext highlighter-rouge">container</code> netmode.</p> <p>Example running a Redis container with Redis binding to <code class="language-plaintext highlighter-rouge">localhost</code> then running the <code class="language-plaintext highlighter-rouge">redis-cli</code> command and connecting to the Redis server over the <code class="language-plaintext highlighter-rouge">localhost</code> interface.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -d --name redis example/redis --bind 127.0.0.1
+$ # use the redis container's network stack to access localhost
+$ docker run --rm -it --network container:redis example/redis-cli -h 127.0.0.1
+</pre></div> <h4 id="user-defined-network">User-defined network</h4> <p>You can create a network using a Docker network driver or an external network driver plugin. You can connect multiple containers to the same network. Once connected to a user-defined network, the containers can communicate easily using only another container’s IP address or name.</p> <p>For <code class="language-plaintext highlighter-rouge">overlay</code> networks or custom plugins that support multi-host connectivity, containers connected to the same multi-host network but launched from different Engines can also communicate in this way.</p> <p>The following example creates a network using the built-in <code class="language-plaintext highlighter-rouge">bridge</code> network driver and running a container in the created network</p> <div class="highlight"><pre class="highlight" data-language="">$ docker network create -d bridge my-net
+$ docker run --network=my-net -itd --name=container3 busybox
+</pre></div> <h3 id="managing-etchosts">Managing /etc/hosts</h3> <p>Your container will have lines in <code class="language-plaintext highlighter-rouge">/etc/hosts</code> which define the hostname of the container itself as well as <code class="language-plaintext highlighter-rouge">localhost</code> and a few other common things. The <code class="language-plaintext highlighter-rouge">--add-host</code> flag can be used to add additional lines to <code class="language-plaintext highlighter-rouge">/etc/hosts</code>.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --add-host db-static:86.75.30.9 ubuntu cat /etc/hosts
+
+172.17.0.22 09d03f76bf2c
+fe00::0 ip6-localnet
+ff00::0 ip6-mcastprefix
+ff02::1 ip6-allnodes
+ff02::2 ip6-allrouters
+127.0.0.1 localhost
+::1 localhost ip6-localhost ip6-loopback
+86.75.30.9 db-static
+</pre></div> <p>If a container is connected to the default bridge network and <code class="language-plaintext highlighter-rouge">linked</code> with other containers, then the container’s <code class="language-plaintext highlighter-rouge">/etc/hosts</code> file is updated with the linked container’s name.</p> <blockquote> <p><strong>Note</strong></p> <p>Since Docker may live update the container’s <code class="language-plaintext highlighter-rouge">/etc/hosts</code> file, there may be situations when processes inside the container can end up reading an empty or incomplete <code class="language-plaintext highlighter-rouge">/etc/hosts</code> file. In most cases, retrying the read again should fix the problem.</p> </blockquote> <h2 id="restart-policies---restart">Restart policies (--restart)</h2> <p>Using the <code class="language-plaintext highlighter-rouge">--restart</code> flag on Docker run you can specify a restart policy for how a container should or should not be restarted on exit.</p> <p>When a restart policy is active on a container, it will be shown as either <code class="language-plaintext highlighter-rouge">Up</code> or <code class="language-plaintext highlighter-rouge">Restarting</code> in <a href="../commandline/ps/index"><code class="language-plaintext highlighter-rouge">docker ps</code></a>. It can also be useful to use <a href="../commandline/events/index"><code class="language-plaintext highlighter-rouge">docker events</code></a> to see the restart policy in effect.</p> <p>Docker supports the following restart policies:</p> <table> <thead> <tr> <th>Policy</th> <th>Result</th> </tr> </thead> <tbody> <tr> <td><strong>no</strong></td> <td>Do not automatically restart the container when it exits. This is the default.</td> </tr> <tr> <td><span style="white-space: nowrap"> <strong>on-failure</strong>[:max-retries] </span></td> <td>Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts.</td> </tr> <tr> <td><strong>always</strong></td> <td>Always restart the container regardless of the exit status. When you specify always, the Docker daemon will try to restart the container indefinitely. The container will also always start on daemon startup, regardless of the current state of the container.</td> </tr> <tr> <td><strong>unless-stopped</strong></td> <td>Always restart the container regardless of the exit status, including on daemon startup, except if the container was put into a stopped state before the Docker daemon was stopped.</td> </tr> </tbody> </table> <p>An increasing delay (double the previous delay, starting at 100 milliseconds) is added before each restart to prevent flooding the server. This means the daemon will wait for 100 ms, then 200 ms, 400, 800, 1600, and so on until either the <code class="language-plaintext highlighter-rouge">on-failure</code> limit, the maximum delay of 1 minute is hit, or when you <code class="language-plaintext highlighter-rouge">docker stop</code> or <code class="language-plaintext highlighter-rouge">docker rm -f</code> the container.</p> <p>If a container is successfully restarted (the container is started and runs for at least 10 seconds), the delay is reset to its default value of 100 ms.</p> <p>You can specify the maximum amount of times Docker will try to restart the container when using the <strong>on-failure</strong> policy. The default is that Docker will try forever to restart the container. The number of (attempted) restarts for a container can be obtained via <a href="../commandline/inspect/index"><code class="language-plaintext highlighter-rouge">docker inspect</code></a>. For example, to get the number of restarts for container “my-container”;</p> <div class="highlight"><pre class="highlight" data-language="">
+$ docker inspect -f "{{ .RestartCount }}" my-container
+# 2
+
+</pre></div> <p>Or, to get the last time the container was (re)started;</p> <div class="highlight"><pre class="highlight" data-language="">
+$ docker inspect -f "{{ .State.StartedAt }}" my-container
+# 2015-03-04T23:47:07.691840179Z
+
+</pre></div> <p>Combining <code class="language-plaintext highlighter-rouge">--restart</code> (restart policy) with the <code class="language-plaintext highlighter-rouge">--rm</code> (clean up) flag results in an error. On container restart, attached clients are disconnected. See the examples on using the <a href="#clean-up---rm"><code class="language-plaintext highlighter-rouge">--rm</code> (clean up)</a> flag later in this page.</p> <h3 id="examples">Examples</h3> <div class="highlight"><pre class="highlight" data-language="">$ docker run --restart=always redis
+</pre></div> <p>This will run the <code class="language-plaintext highlighter-rouge">redis</code> container with a restart policy of <strong>always</strong> so that if the container exits, Docker will restart it.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --restart=on-failure:10 redis
+</pre></div> <p>This will run the <code class="language-plaintext highlighter-rouge">redis</code> container with a restart policy of <strong>on-failure</strong> and a maximum restart count of 10. If the <code class="language-plaintext highlighter-rouge">redis</code> container exits with a non-zero exit status more than 10 times in a row Docker will abort trying to restart the container. Providing a maximum restart limit is only valid for the <strong>on-failure</strong> policy.</p> <h2 id="exit-status">Exit Status</h2> <p>The exit code from <code class="language-plaintext highlighter-rouge">docker run</code> gives information about why the container failed to run or why it exited. When <code class="language-plaintext highlighter-rouge">docker run</code> exits with a non-zero code, the exit codes follow the <code class="language-plaintext highlighter-rouge">chroot</code> standard, see below:</p> <p><strong><em>125</em></strong> if the error is with Docker daemon <strong><em>itself</em></strong></p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --foo busybox; echo $?
+
+flag provided but not defined: --foo
+See 'docker run --help'.
+125
+</pre></div> <p><strong><em>126</em></strong> if the <strong><em>contained command</em></strong> cannot be invoked</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run busybox /etc; echo $?
+
+docker: Error response from daemon: Container command '/etc' could not be invoked.
+126
+</pre></div> <p><strong><em>127</em></strong> if the <strong><em>contained command</em></strong> cannot be found</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run busybox foo; echo $?
+
+docker: Error response from daemon: Container command 'foo' not found or does not exist.
+127
+</pre></div> <p><strong><em>Exit code</em></strong> of <strong><em>contained command</em></strong> otherwise</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run busybox /bin/sh -c 'exit 3'
+$ echo $?
+3
+</pre></div> <h2 id="clean-up---rm">Clean up (--rm)</h2> <p>By default a container’s file system persists even after the container exits. This makes debugging a lot easier (since you can inspect the final state) and you retain all your data by default. But if you are running short-term <strong>foreground</strong> processes, these container file systems can really pile up. If instead you’d like Docker to <strong>automatically clean up the container and remove the file system when the container exits</strong>, you can add the <code class="language-plaintext highlighter-rouge">--rm</code> flag:</p> <div class="highlight"><pre class="highlight" data-language="">--rm=false: Automatically remove the container when it exits
+</pre></div> <blockquote> <p><strong>Note</strong></p> <p>If you set the <code class="language-plaintext highlighter-rouge">--rm</code> flag, Docker also removes the anonymous volumes associated with the container when the container is removed. This is similar to running <code class="language-plaintext highlighter-rouge">docker rm -v my-container</code>. Only volumes that are specified without a name are removed. For example, when running:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --rm -v /foo -v awesome:/bar busybox top
+</pre></div> <p>the volume for <code class="language-plaintext highlighter-rouge">/foo</code> will be removed, but the volume for <code class="language-plaintext highlighter-rouge">/bar</code> will not. Volumes inherited via <code class="language-plaintext highlighter-rouge">--volumes-from</code> will be removed with the same logic: if the original volume was specified with a name it will <strong>not</strong> be removed.</p> </blockquote> <h2 id="security-configuration">Security configuration</h2> <table> <thead> <tr> <th style="text-align: left">Option</th> <th style="text-align: left">Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--security-opt="label=user:USER"</code></td> <td style="text-align: left">Set the label user for the container</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--security-opt="label=role:ROLE"</code></td> <td style="text-align: left">Set the label role for the container</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--security-opt="label=type:TYPE"</code></td> <td style="text-align: left">Set the label type for the container</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--security-opt="label=level:LEVEL"</code></td> <td style="text-align: left">Set the label level for the container</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--security-opt="label=disable"</code></td> <td style="text-align: left">Turn off label confinement for the container</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--security-opt="apparmor=PROFILE"</code></td> <td style="text-align: left">Set the apparmor profile to be applied to the container</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--security-opt="no-new-privileges:true"</code></td> <td style="text-align: left">Disable container processes from gaining new privileges</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--security-opt="seccomp=unconfined"</code></td> <td style="text-align: left">Turn off seccomp confinement for the container</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--security-opt="seccomp=profile.json"</code></td> <td style="text-align: left">White-listed syscalls seccomp Json file to be used as a seccomp filter</td> </tr> </tbody> </table> <p>You can override the default labeling scheme for each container by specifying the <code class="language-plaintext highlighter-rouge">--security-opt</code> flag. Specifying the level in the following command allows you to share the same content between containers.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --security-opt label=level:s0:c100,c200 -it fedora bash
+</pre></div> <blockquote> <p><strong>Note</strong></p> <p>Automatic translation of MLS labels is not currently supported.</p> </blockquote> <p>To disable the security labeling for this container versus running with the <code class="language-plaintext highlighter-rouge">--privileged</code> flag, use the following command:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --security-opt label=disable -it fedora bash
+</pre></div> <p>If you want a tighter security policy on the processes within a container, you can specify an alternate type for the container. You could run a container that is only allowed to listen on Apache ports by executing the following command:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --security-opt label=type:svirt_apache_t -it centos bash
+</pre></div> <blockquote> <p><strong>Note</strong></p> <p>You would have to write policy defining a <code class="language-plaintext highlighter-rouge">svirt_apache_t</code> type.</p> </blockquote> <p>If you want to prevent your container processes from gaining additional privileges, you can execute the following command:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --security-opt no-new-privileges -it centos bash
+</pre></div> <p>This means that commands that raise privileges such as <code class="language-plaintext highlighter-rouge">su</code> or <code class="language-plaintext highlighter-rouge">sudo</code> will no longer work. It also causes any seccomp filters to be applied later, after privileges have been dropped which may mean you can have a more restrictive set of filters. For more details, see the <a href="https://www.kernel.org/doc/Documentation/prctl/no_new_privs.txt">kernel documentation</a>.</p> <h2 id="specify-an-init-process">Specify an init process</h2> <p>You can use the <code class="language-plaintext highlighter-rouge">--init</code> flag to indicate that an init process should be used as the PID 1 in the container. Specifying an init process ensures the usual responsibilities of an init system, such as reaping zombie processes, are performed inside the created container.</p> <p>The default init process used is the first <code class="language-plaintext highlighter-rouge">docker-init</code> executable found in the system path of the Docker daemon process. This <code class="language-plaintext highlighter-rouge">docker-init</code> binary, included in the default installation, is backed by <a href="https://github.com/krallin/tini">tini</a>.</p> <h2 id="specify-custom-cgroups">Specify custom cgroups</h2> <p>Using the <code class="language-plaintext highlighter-rouge">--cgroup-parent</code> flag, you can pass a specific cgroup to run a container in. This allows you to create and manage cgroups on their own. You can define custom resources for those cgroups and put containers under a common parent group.</p> <h2 id="runtime-constraints-on-resources">Runtime constraints on resources</h2> <p>The operator can also adjust the performance parameters of the container:</p> <table> <thead> <tr> <th style="text-align: left">Option</th> <th style="text-align: left">Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left">
+<code class="language-plaintext highlighter-rouge">-m</code>, <code class="language-plaintext highlighter-rouge">--memory=""</code>
+</td> <td style="text-align: left">Memory limit (format: <code class="language-plaintext highlighter-rouge">&lt;number&gt;[&lt;unit&gt;]</code>). Number is a positive integer. Unit can be one of <code class="language-plaintext highlighter-rouge">b</code>, <code class="language-plaintext highlighter-rouge">k</code>, <code class="language-plaintext highlighter-rouge">m</code>, or <code class="language-plaintext highlighter-rouge">g</code>. Minimum is 4M.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--memory-swap=""</code></td> <td style="text-align: left">Total memory limit (memory + swap, format: <code class="language-plaintext highlighter-rouge">&lt;number&gt;[&lt;unit&gt;]</code>). Number is a positive integer. Unit can be one of <code class="language-plaintext highlighter-rouge">b</code>, <code class="language-plaintext highlighter-rouge">k</code>, <code class="language-plaintext highlighter-rouge">m</code>, or <code class="language-plaintext highlighter-rouge">g</code>.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--memory-reservation=""</code></td> <td style="text-align: left">Memory soft limit (format: <code class="language-plaintext highlighter-rouge">&lt;number&gt;[&lt;unit&gt;]</code>). Number is a positive integer. Unit can be one of <code class="language-plaintext highlighter-rouge">b</code>, <code class="language-plaintext highlighter-rouge">k</code>, <code class="language-plaintext highlighter-rouge">m</code>, or <code class="language-plaintext highlighter-rouge">g</code>.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--kernel-memory=""</code></td> <td style="text-align: left">Kernel memory limit (format: <code class="language-plaintext highlighter-rouge">&lt;number&gt;[&lt;unit&gt;]</code>). Number is a positive integer. Unit can be one of <code class="language-plaintext highlighter-rouge">b</code>, <code class="language-plaintext highlighter-rouge">k</code>, <code class="language-plaintext highlighter-rouge">m</code>, or <code class="language-plaintext highlighter-rouge">g</code>. Minimum is 4M.</td> </tr> <tr> <td style="text-align: left">
+<code class="language-plaintext highlighter-rouge">-c</code>, <code class="language-plaintext highlighter-rouge">--cpu-shares=0</code>
+</td> <td style="text-align: left">CPU shares (relative weight)</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--cpus=0.000</code></td> <td style="text-align: left">Number of CPUs. Number is a fractional number. 0.000 means no limit.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--cpu-period=0</code></td> <td style="text-align: left">Limit the CPU CFS (Completely Fair Scheduler) period</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--cpuset-cpus=""</code></td> <td style="text-align: left">CPUs in which to allow execution (0-3, 0,1)</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--cpuset-mems=""</code></td> <td style="text-align: left">Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--cpu-quota=0</code></td> <td style="text-align: left">Limit the CPU CFS (Completely Fair Scheduler) quota</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--cpu-rt-period=0</code></td> <td style="text-align: left">Limit the CPU real-time period. In microseconds. Requires parent cgroups be set and cannot be higher than parent. Also check rtprio ulimits.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--cpu-rt-runtime=0</code></td> <td style="text-align: left">Limit the CPU real-time runtime. In microseconds. Requires parent cgroups be set and cannot be higher than parent. Also check rtprio ulimits.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--blkio-weight=0</code></td> <td style="text-align: left">Block IO weight (relative weight) accepts a weight value between 10 and 1000.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--blkio-weight-device=""</code></td> <td style="text-align: left">Block IO weight (relative device weight, format: <code class="language-plaintext highlighter-rouge">DEVICE_NAME:WEIGHT</code>)</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--device-read-bps=""</code></td> <td style="text-align: left">Limit read rate from a device (format: <code class="language-plaintext highlighter-rouge">&lt;device-path&gt;:&lt;number&gt;[&lt;unit&gt;]</code>). Number is a positive integer. Unit can be one of <code class="language-plaintext highlighter-rouge">kb</code>, <code class="language-plaintext highlighter-rouge">mb</code>, or <code class="language-plaintext highlighter-rouge">gb</code>.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--device-write-bps=""</code></td> <td style="text-align: left">Limit write rate to a device (format: <code class="language-plaintext highlighter-rouge">&lt;device-path&gt;:&lt;number&gt;[&lt;unit&gt;]</code>). Number is a positive integer. Unit can be one of <code class="language-plaintext highlighter-rouge">kb</code>, <code class="language-plaintext highlighter-rouge">mb</code>, or <code class="language-plaintext highlighter-rouge">gb</code>.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--device-read-iops=""</code></td> <td style="text-align: left">Limit read rate (IO per second) from a device (format: <code class="language-plaintext highlighter-rouge">&lt;device-path&gt;:&lt;number&gt;</code>). Number is a positive integer.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--device-write-iops=""</code></td> <td style="text-align: left">Limit write rate (IO per second) to a device (format: <code class="language-plaintext highlighter-rouge">&lt;device-path&gt;:&lt;number&gt;</code>). Number is a positive integer.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--oom-kill-disable=false</code></td> <td style="text-align: left">Whether to disable OOM Killer for the container or not.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--oom-score-adj=0</code></td> <td style="text-align: left">Tune container’s OOM preferences (-1000 to 1000)</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--memory-swappiness=""</code></td> <td style="text-align: left">Tune a container’s memory swappiness behavior. Accepts an integer between 0 and 100.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--shm-size=""</code></td> <td style="text-align: left">Size of <code class="language-plaintext highlighter-rouge">/dev/shm</code>. The format is <code class="language-plaintext highlighter-rouge">&lt;number&gt;&lt;unit&gt;</code>. <code class="language-plaintext highlighter-rouge">number</code> must be greater than <code class="language-plaintext highlighter-rouge">0</code>. Unit is optional and can be <code class="language-plaintext highlighter-rouge">b</code> (bytes), <code class="language-plaintext highlighter-rouge">k</code> (kilobytes), <code class="language-plaintext highlighter-rouge">m</code> (megabytes), or <code class="language-plaintext highlighter-rouge">g</code> (gigabytes). If you omit the unit, the system uses bytes. If you omit the size entirely, the system uses <code class="language-plaintext highlighter-rouge">64m</code>.</td> </tr> </tbody> </table> <h3 id="user-memory-constraints">User memory constraints</h3> <p>We have four ways to set user memory usage:</p> <table> <thead> <tr> <th>Option</th> <th>Result</th> </tr> </thead> <tbody> <tr> <td class="no-wrap">
+<strong>memory=inf, memory-swap=inf</strong> (default)</td> <td>There is no memory limit for the container. The container can use as much memory as needed.</td> </tr> <tr> <td class="no-wrap"><strong>memory=L&lt;inf, memory-swap=inf</strong></td> <td>(specify memory and set memory-swap as <code class="language-plaintext highlighter-rouge">-1</code>) The container is not allowed to use more than L bytes of memory, but can use as much swap as is needed (if the host supports swap memory).</td> </tr> <tr> <td class="no-wrap"><strong>memory=L&lt;inf, memory-swap=2*L</strong></td> <td>(specify memory without memory-swap) The container is not allowed to use more than L bytes of memory, swap <em>plus</em> memory usage is double of that.</td> </tr> <tr> <td class="no-wrap"><strong>memory=L&lt;inf, memory-swap=S&lt;inf, L&lt;=S</strong></td> <td>(specify both memory and memory-swap) The container is not allowed to use more than L bytes of memory, swap <em>plus</em> memory usage is limited by S.</td> </tr> </tbody> </table> <p>Examples:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it ubuntu:14.04 /bin/bash
+</pre></div> <p>We set nothing about memory, this means the processes in the container can use as much memory and swap memory as they need.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it -m 300M --memory-swap -1 ubuntu:14.04 /bin/bash
+</pre></div> <p>We set memory limit and disabled swap memory limit, this means the processes in the container can use 300M memory and as much swap memory as they need (if the host supports swap memory).</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it -m 300M ubuntu:14.04 /bin/bash
+</pre></div> <p>We set memory limit only, this means the processes in the container can use 300M memory and 300M swap memory, by default, the total virtual memory size (--memory-swap) will be set as double of memory, in this case, memory + swap would be 2*300M, so processes can use 300M swap memory as well.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it -m 300M --memory-swap 1G ubuntu:14.04 /bin/bash
+</pre></div> <p>We set both memory and swap memory, so the processes in the container can use 300M memory and 700M swap memory.</p> <p>Memory reservation is a kind of memory soft limit that allows for greater sharing of memory. Under normal circumstances, containers can use as much of the memory as needed and are constrained only by the hard limits set with the <code class="language-plaintext highlighter-rouge">-m</code>/<code class="language-plaintext highlighter-rouge">--memory</code> option. When memory reservation is set, Docker detects memory contention or low memory and forces containers to restrict their consumption to a reservation limit.</p> <p>Always set the memory reservation value below the hard limit, otherwise the hard limit takes precedence. A reservation of 0 is the same as setting no reservation. By default (without reservation set), memory reservation is the same as the hard memory limit.</p> <p>Memory reservation is a soft-limit feature and does not guarantee the limit won’t be exceeded. Instead, the feature attempts to ensure that, when memory is heavily contended for, memory is allocated based on the reservation hints/setup.</p> <p>The following example limits the memory (<code class="language-plaintext highlighter-rouge">-m</code>) to 500M and sets the memory reservation to 200M.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it -m 500M --memory-reservation 200M ubuntu:14.04 /bin/bash
+</pre></div> <p>Under this configuration, when the container consumes memory more than 200M and less than 500M, the next system memory reclaim attempts to shrink container memory below 200M.</p> <p>The following example set memory reservation to 1G without a hard memory limit.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --memory-reservation 1G ubuntu:14.04 /bin/bash
+</pre></div> <p>The container can use as much memory as it needs. The memory reservation setting ensures the container doesn’t consume too much memory for long time, because every memory reclaim shrinks the container’s consumption to the reservation.</p> <p>By default, kernel kills processes in a container if an out-of-memory (OOM) error occurs. To change this behaviour, use the <code class="language-plaintext highlighter-rouge">--oom-kill-disable</code> option. Only disable the OOM killer on containers where you have also set the <code class="language-plaintext highlighter-rouge">-m/--memory</code> option. If the <code class="language-plaintext highlighter-rouge">-m</code> flag is not set, this can result in the host running out of memory and require killing the host’s system processes to free memory.</p> <p>The following example limits the memory to 100M and disables the OOM killer for this container:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it -m 100M --oom-kill-disable ubuntu:14.04 /bin/bash
+</pre></div> <p>The following example, illustrates a dangerous way to use the flag:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --oom-kill-disable ubuntu:14.04 /bin/bash
+</pre></div> <p>The container has unlimited memory which can cause the host to run out memory and require killing system processes to free memory. The <code class="language-plaintext highlighter-rouge">--oom-score-adj</code> parameter can be changed to select the priority of which containers will be killed when the system is out of memory, with negative scores making them less likely to be killed, and positive scores more likely.</p> <h3 id="kernel-memory-constraints">Kernel memory constraints</h3> <p>Kernel memory is fundamentally different than user memory as kernel memory can’t be swapped out. The inability to swap makes it possible for the container to block system services by consuming too much kernel memory. Kernel memory includes:</p> <ul> <li>stack pages</li> <li>slab pages</li> <li>sockets memory pressure</li> <li>tcp memory pressure</li> </ul> <p>You can setup kernel memory limit to constrain these kinds of memory. For example, every process consumes some stack pages. By limiting kernel memory, you can prevent new processes from being created when the kernel memory usage is too high.</p> <p>Kernel memory is never completely independent of user memory. Instead, you limit kernel memory in the context of the user memory limit. Assume “U” is the user memory limit and “K” the kernel limit. There are three possible ways to set limits:</p> <table> <thead> <tr> <th>Option</th> <th>Result</th> </tr> </thead> <tbody> <tr> <td class="no-wrap">
+<strong>U != 0, K = inf</strong> (default)</td> <td>This is the standard memory limitation mechanism already present before using kernel memory. Kernel memory is completely ignored.</td> </tr> <tr> <td class="no-wrap"><strong>U != 0, K &lt; U</strong></td> <td>Kernel memory is a subset of the user memory. This setup is useful in deployments where the total amount of memory per-cgroup is overcommitted. Overcommitting kernel memory limits is definitely not recommended, since the box can still run out of non-reclaimable memory. In this case, you can configure K so that the sum of all groups is never greater than the total memory. Then, freely set U at the expense of the system's service quality.</td> </tr> <tr> <td class="no-wrap"><strong>U != 0, K &gt; U</strong></td> <td>Since kernel memory charges are also fed to the user counter and reclamation is triggered for the container for both kinds of memory. This configuration gives the admin a unified view of memory. It is also useful for people who just want to track kernel memory usage.</td> </tr> </tbody> </table> <p>Examples:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it -m 500M --kernel-memory 50M ubuntu:14.04 /bin/bash
+</pre></div> <p>We set memory and kernel memory, so the processes in the container can use 500M memory in total, in this 500M memory, it can be 50M kernel memory tops.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --kernel-memory 50M ubuntu:14.04 /bin/bash
+</pre></div> <p>We set kernel memory without <strong>-m</strong>, so the processes in the container can use as much memory as they want, but they can only use 50M kernel memory.</p> <h3 id="swappiness-constraint">Swappiness constraint</h3> <p>By default, a container’s kernel can swap out a percentage of anonymous pages. To set this percentage for a container, specify a <code class="language-plaintext highlighter-rouge">--memory-swappiness</code> value between 0 and 100. A value of 0 turns off anonymous page swapping. A value of 100 sets all anonymous pages as swappable. By default, if you are not using <code class="language-plaintext highlighter-rouge">--memory-swappiness</code>, memory swappiness value will be inherited from the parent.</p> <p>For example, you can set:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --memory-swappiness=0 ubuntu:14.04 /bin/bash
+</pre></div> <p>Setting the <code class="language-plaintext highlighter-rouge">--memory-swappiness</code> option is helpful when you want to retain the container’s working set and to avoid swapping performance penalties.</p> <h3 id="cpu-share-constraint">CPU share constraint</h3> <p>By default, all containers get the same proportion of CPU cycles. This proportion can be modified by changing the container’s CPU share weighting relative to the weighting of all other running containers.</p> <p>To modify the proportion from the default of 1024, use the <code class="language-plaintext highlighter-rouge">-c</code> or <code class="language-plaintext highlighter-rouge">--cpu-shares</code> flag to set the weighting to 2 or higher. If 0 is set, the system will ignore the value and use the default of 1024.</p> <p>The proportion will only apply when CPU-intensive processes are running. When tasks in one container are idle, other containers can use the left-over CPU time. The actual amount of CPU time will vary depending on the number of containers running on the system.</p> <p>For example, consider three containers, one has a cpu-share of 1024 and two others have a cpu-share setting of 512. When processes in all three containers attempt to use 100% of CPU, the first container would receive 50% of the total CPU time. If you add a fourth container with a cpu-share of 1024, the first container only gets 33% of the CPU. The remaining containers receive 16.5%, 16.5% and 33% of the CPU.</p> <p>On a multi-core system, the shares of CPU time are distributed over all CPU cores. Even if a container is limited to less than 100% of CPU time, it can use 100% of each individual CPU core.</p> <p>For example, consider a system with more than three cores. If you start one container <code class="language-plaintext highlighter-rouge">{C0}</code> with <code class="language-plaintext highlighter-rouge">-c=512</code> running one process, and another container <code class="language-plaintext highlighter-rouge">{C1}</code> with <code class="language-plaintext highlighter-rouge">-c=1024</code> running two processes, this can result in the following division of CPU shares:</p> <div class="highlight"><pre class="highlight" data-language="">PID container CPU CPU share
+100 {C0} 0 100% of CPU0
+101 {C1} 1 100% of CPU1
+102 {C1} 2 100% of CPU2
+</pre></div> <h3 id="cpu-period-constraint">CPU period constraint</h3> <p>The default CPU CFS (Completely Fair Scheduler) period is 100ms. We can use <code class="language-plaintext highlighter-rouge">--cpu-period</code> to set the period of CPUs to limit the container’s CPU usage. And usually <code class="language-plaintext highlighter-rouge">--cpu-period</code> should work with <code class="language-plaintext highlighter-rouge">--cpu-quota</code>.</p> <p>Examples:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --cpu-period=50000 --cpu-quota=25000 ubuntu:14.04 /bin/bash
+</pre></div> <p>If there is 1 CPU, this means the container can get 50% CPU worth of run-time every 50ms.</p> <p>In addition to use <code class="language-plaintext highlighter-rouge">--cpu-period</code> and <code class="language-plaintext highlighter-rouge">--cpu-quota</code> for setting CPU period constraints, it is possible to specify <code class="language-plaintext highlighter-rouge">--cpus</code> with a float number to achieve the same purpose. For example, if there is 1 CPU, then <code class="language-plaintext highlighter-rouge">--cpus=0.5</code> will achieve the same result as setting <code class="language-plaintext highlighter-rouge">--cpu-period=50000</code> and <code class="language-plaintext highlighter-rouge">--cpu-quota=25000</code> (50% CPU).</p> <p>The default value for <code class="language-plaintext highlighter-rouge">--cpus</code> is <code class="language-plaintext highlighter-rouge">0.000</code>, which means there is no limit.</p> <p>For more information, see the <a href="https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt">CFS documentation on bandwidth limiting</a>.</p> <h3 id="cpuset-constraint">Cpuset constraint</h3> <p>We can set cpus in which to allow execution for containers.</p> <p>Examples:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --cpuset-cpus="1,3" ubuntu:14.04 /bin/bash
+</pre></div> <p>This means processes in container can be executed on cpu 1 and cpu 3.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --cpuset-cpus="0-2" ubuntu:14.04 /bin/bash
+</pre></div> <p>This means processes in container can be executed on cpu 0, cpu 1 and cpu 2.</p> <p>We can set mems in which to allow execution for containers. Only effective on NUMA systems.</p> <p>Examples:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --cpuset-mems="1,3" ubuntu:14.04 /bin/bash
+</pre></div> <p>This example restricts the processes in the container to only use memory from memory nodes 1 and 3.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --cpuset-mems="0-2" ubuntu:14.04 /bin/bash
+</pre></div> <p>This example restricts the processes in the container to only use memory from memory nodes 0, 1 and 2.</p> <h3 id="cpu-quota-constraint">CPU quota constraint</h3> <p>The <code class="language-plaintext highlighter-rouge">--cpu-quota</code> flag limits the container’s CPU usage. The default 0 value allows the container to take 100% of a CPU resource (1 CPU). The CFS (Completely Fair Scheduler) handles resource allocation for executing processes and is default Linux Scheduler used by the kernel. Set this value to 50000 to limit the container to 50% of a CPU resource. For multiple CPUs, adjust the <code class="language-plaintext highlighter-rouge">--cpu-quota</code> as necessary. For more information, see the <a href="https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt">CFS documentation on bandwidth limiting</a>.</p> <h3 id="block-io-bandwidth-blkio-constraint">Block IO bandwidth (Blkio) constraint</h3> <p>By default, all containers get the same proportion of block IO bandwidth (blkio). This proportion is 500. To modify this proportion, change the container’s blkio weight relative to the weighting of all other running containers using the <code class="language-plaintext highlighter-rouge">--blkio-weight</code> flag.</p> <blockquote> <p><strong>Note:</strong></p> <p>The blkio weight setting is only available for direct IO. Buffered IO is not currently supported.</p> </blockquote> <p>The <code class="language-plaintext highlighter-rouge">--blkio-weight</code> flag can set the weighting to a value between 10 to 1000. For example, the commands below create two containers with different blkio weight:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --name c1 --blkio-weight 300 ubuntu:14.04 /bin/bash
+$ docker run -it --name c2 --blkio-weight 600 ubuntu:14.04 /bin/bash
+</pre></div> <p>If you do block IO in the two containers at the same time, by, for example:</p> <div class="highlight"><pre class="highlight" data-language="">$ time dd if=/mnt/zerofile of=test.out bs=1M count=1024 oflag=direct
+</pre></div> <p>You’ll find that the proportion of time is the same as the proportion of blkio weights of the two containers.</p> <p>The <code class="language-plaintext highlighter-rouge">--blkio-weight-device="DEVICE_NAME:WEIGHT"</code> flag sets a specific device weight. The <code class="language-plaintext highlighter-rouge">DEVICE_NAME:WEIGHT</code> is a string containing a colon-separated device name and weight. For example, to set <code class="language-plaintext highlighter-rouge">/dev/sda</code> device weight to <code class="language-plaintext highlighter-rouge">200</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it \
+ --blkio-weight-device "/dev/sda:200" \
+ ubuntu
+</pre></div> <p>If you specify both the <code class="language-plaintext highlighter-rouge">--blkio-weight</code> and <code class="language-plaintext highlighter-rouge">--blkio-weight-device</code>, Docker uses the <code class="language-plaintext highlighter-rouge">--blkio-weight</code> as the default weight and uses <code class="language-plaintext highlighter-rouge">--blkio-weight-device</code> to override this default with a new value on a specific device. The following example uses a default weight of <code class="language-plaintext highlighter-rouge">300</code> and overrides this default on <code class="language-plaintext highlighter-rouge">/dev/sda</code> setting that weight to <code class="language-plaintext highlighter-rouge">200</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it \
+ --blkio-weight 300 \
+ --blkio-weight-device "/dev/sda:200" \
+ ubuntu
+</pre></div> <p>The <code class="language-plaintext highlighter-rouge">--device-read-bps</code> flag limits the read rate (bytes per second) from a device. For example, this command creates a container and limits the read rate to <code class="language-plaintext highlighter-rouge">1mb</code> per second from <code class="language-plaintext highlighter-rouge">/dev/sda</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --device-read-bps /dev/sda:1mb ubuntu
+</pre></div> <p>The <code class="language-plaintext highlighter-rouge">--device-write-bps</code> flag limits the write rate (bytes per second) to a device. For example, this command creates a container and limits the write rate to <code class="language-plaintext highlighter-rouge">1mb</code> per second for <code class="language-plaintext highlighter-rouge">/dev/sda</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --device-write-bps /dev/sda:1mb ubuntu
+</pre></div> <p>Both flags take limits in the <code class="language-plaintext highlighter-rouge">&lt;device-path&gt;:&lt;limit&gt;[unit]</code> format. Both read and write rates must be a positive integer. You can specify the rate in <code class="language-plaintext highlighter-rouge">kb</code> (kilobytes), <code class="language-plaintext highlighter-rouge">mb</code> (megabytes), or <code class="language-plaintext highlighter-rouge">gb</code> (gigabytes).</p> <p>The <code class="language-plaintext highlighter-rouge">--device-read-iops</code> flag limits read rate (IO per second) from a device. For example, this command creates a container and limits the read rate to <code class="language-plaintext highlighter-rouge">1000</code> IO per second from <code class="language-plaintext highlighter-rouge">/dev/sda</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -ti --device-read-iops /dev/sda:1000 ubuntu
+</pre></div> <p>The <code class="language-plaintext highlighter-rouge">--device-write-iops</code> flag limits write rate (IO per second) to a device. For example, this command creates a container and limits the write rate to <code class="language-plaintext highlighter-rouge">1000</code> IO per second to <code class="language-plaintext highlighter-rouge">/dev/sda</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -ti --device-write-iops /dev/sda:1000 ubuntu
+</pre></div> <p>Both flags take limits in the <code class="language-plaintext highlighter-rouge">&lt;device-path&gt;:&lt;limit&gt;</code> format. Both read and write rates must be a positive integer.</p> <h2 id="additional-groups">Additional groups</h2> <div class="highlight"><pre class="highlight" data-language="">--group-add: Add additional groups to run as
+</pre></div> <p>By default, the docker container process runs with the supplementary groups looked up for the specified user. If one wants to add more to that list of groups, then one can use this flag:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --rm --group-add audio --group-add nogroup --group-add 777 busybox id
+
+uid=0(root) gid=0(root) groups=10(wheel),29(audio),99(nogroup),777
+</pre></div> <h2 id="runtime-privilege-and-linux-capabilities">Runtime privilege and Linux capabilities</h2> <table> <thead> <tr> <th style="text-align: left">Option</th> <th style="text-align: left">Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--cap-add</code></td> <td style="text-align: left">Add Linux capabilities</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--cap-drop</code></td> <td style="text-align: left">Drop Linux capabilities</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--privileged</code></td> <td style="text-align: left">Give extended privileges to this container</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">--device=[]</code></td> <td style="text-align: left">Allows you to run devices inside the container without the --privileged flag.</td> </tr> </tbody> </table> <p>By default, Docker containers are “unprivileged” and cannot, for example, run a Docker daemon inside a Docker container. This is because by default a container is not allowed to access any devices, but a “privileged” container is given access to all devices (see the documentation on <a href="https://www.kernel.org/doc/Documentation/cgroup-v1/devices.txt">cgroups devices</a>).</p> <p>The --privileged flag gives all capabilities to the container. When the operator executes <code class="language-plaintext highlighter-rouge">docker run --privileged</code>, Docker will enable access to all devices on the host as well as set some configuration in AppArmor or SELinux to allow the container nearly all the same access to the host as processes running outside containers on the host. Additional information about running with <code class="language-plaintext highlighter-rouge">--privileged</code> is available on the <a href="https://blog.docker.com/2013/09/docker-can-now-run-within-docker/">Docker Blog</a>.</p> <p>If you want to limit access to a specific device or devices you can use the <code class="language-plaintext highlighter-rouge">--device</code> flag. It allows you to specify one or more devices that will be accessible within the container.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --device=/dev/snd:/dev/snd ...
+</pre></div> <p>By default, the container will be able to <code class="language-plaintext highlighter-rouge">read</code>, <code class="language-plaintext highlighter-rouge">write</code>, and <code class="language-plaintext highlighter-rouge">mknod</code> these devices. This can be overridden using a third <code class="language-plaintext highlighter-rouge">:rwm</code> set of options to each <code class="language-plaintext highlighter-rouge">--device</code> flag:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk /dev/xvdc
+
+Command (m for help): q
+$ docker run --device=/dev/sda:/dev/xvdc:r --rm -it ubuntu fdisk /dev/xvdc
+You will not be able to write the partition table.
+
+Command (m for help): q
+
+$ docker run --device=/dev/sda:/dev/xvdc:w --rm -it ubuntu fdisk /dev/xvdc
+ crash....
+
+$ docker run --device=/dev/sda:/dev/xvdc:m --rm -it ubuntu fdisk /dev/xvdc
+fdisk: unable to open /dev/xvdc: Operation not permitted
+</pre></div> <p>In addition to <code class="language-plaintext highlighter-rouge">--privileged</code>, the operator can have fine grain control over the capabilities using <code class="language-plaintext highlighter-rouge">--cap-add</code> and <code class="language-plaintext highlighter-rouge">--cap-drop</code>. By default, Docker has a default list of capabilities that are kept. The following table lists the Linux capability options which are allowed by default and can be dropped.</p> <table> <thead> <tr> <th style="text-align: left">Capability Key</th> <th style="text-align: left">Capability Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left">AUDIT_WRITE</td> <td style="text-align: left">Write records to kernel auditing log.</td> </tr> <tr> <td style="text-align: left">CHOWN</td> <td style="text-align: left">Make arbitrary changes to file UIDs and GIDs (see chown(2)).</td> </tr> <tr> <td style="text-align: left">DAC_OVERRIDE</td> <td style="text-align: left">Bypass file read, write, and execute permission checks.</td> </tr> <tr> <td style="text-align: left">FOWNER</td> <td style="text-align: left">Bypass permission checks on operations that normally require the file system UID of the process to match the UID of the file.</td> </tr> <tr> <td style="text-align: left">FSETID</td> <td style="text-align: left">Don’t clear set-user-ID and set-group-ID permission bits when a file is modified.</td> </tr> <tr> <td style="text-align: left">KILL</td> <td style="text-align: left">Bypass permission checks for sending signals.</td> </tr> <tr> <td style="text-align: left">MKNOD</td> <td style="text-align: left">Create special files using mknod(2).</td> </tr> <tr> <td style="text-align: left">NET_BIND_SERVICE</td> <td style="text-align: left">Bind a socket to internet domain privileged ports (port numbers less than 1024).</td> </tr> <tr> <td style="text-align: left">NET_RAW</td> <td style="text-align: left">Use RAW and PACKET sockets.</td> </tr> <tr> <td style="text-align: left">SETFCAP</td> <td style="text-align: left">Set file capabilities.</td> </tr> <tr> <td style="text-align: left">SETGID</td> <td style="text-align: left">Make arbitrary manipulations of process GIDs and supplementary GID list.</td> </tr> <tr> <td style="text-align: left">SETPCAP</td> <td style="text-align: left">Modify process capabilities.</td> </tr> <tr> <td style="text-align: left">SETUID</td> <td style="text-align: left">Make arbitrary manipulations of process UIDs.</td> </tr> <tr> <td style="text-align: left">SYS_CHROOT</td> <td style="text-align: left">Use chroot(2), change root directory.</td> </tr> </tbody> </table> <p>The next table shows the capabilities which are not granted by default and may be added.</p> <table> <thead> <tr> <th style="text-align: left">Capability Key</th> <th style="text-align: left">Capability Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left">AUDIT_CONTROL</td> <td style="text-align: left">Enable and disable kernel auditing; change auditing filter rules; retrieve auditing status and filtering rules.</td> </tr> <tr> <td style="text-align: left">AUDIT_READ</td> <td style="text-align: left">Allow reading the audit log via multicast netlink socket.</td> </tr> <tr> <td style="text-align: left">BLOCK_SUSPEND</td> <td style="text-align: left">Allow preventing system suspends.</td> </tr> <tr> <td style="text-align: left">BPF</td> <td style="text-align: left">Allow creating BPF maps, loading BPF Type Format (BTF) data, retrieve JITed code of BPF programs, and more.</td> </tr> <tr> <td style="text-align: left">CHECKPOINT_RESTORE</td> <td style="text-align: left">Allow checkpoint/restore related operations. Introduced in kernel 5.9.</td> </tr> <tr> <td style="text-align: left">DAC_READ_SEARCH</td> <td style="text-align: left">Bypass file read permission checks and directory read and execute permission checks.</td> </tr> <tr> <td style="text-align: left">IPC_LOCK</td> <td style="text-align: left">Lock memory (mlock(2), mlockall(2), mmap(2), shmctl(2)).</td> </tr> <tr> <td style="text-align: left">IPC_OWNER</td> <td style="text-align: left">Bypass permission checks for operations on System V IPC objects.</td> </tr> <tr> <td style="text-align: left">LEASE</td> <td style="text-align: left">Establish leases on arbitrary files (see fcntl(2)).</td> </tr> <tr> <td style="text-align: left">LINUX_IMMUTABLE</td> <td style="text-align: left">Set the FS_APPEND_FL and FS_IMMUTABLE_FL i-node flags.</td> </tr> <tr> <td style="text-align: left">MAC_ADMIN</td> <td style="text-align: left">Allow MAC configuration or state changes. Implemented for the Smack LSM.</td> </tr> <tr> <td style="text-align: left">MAC_OVERRIDE</td> <td style="text-align: left">Override Mandatory Access Control (MAC). Implemented for the Smack Linux Security Module (LSM).</td> </tr> <tr> <td style="text-align: left">NET_ADMIN</td> <td style="text-align: left">Perform various network-related operations.</td> </tr> <tr> <td style="text-align: left">NET_BROADCAST</td> <td style="text-align: left">Make socket broadcasts, and listen to multicasts.</td> </tr> <tr> <td style="text-align: left">PERFMON</td> <td style="text-align: left">Allow system performance and observability privileged operations using perf_events, i915_perf and other kernel subsystems</td> </tr> <tr> <td style="text-align: left">SYS_ADMIN</td> <td style="text-align: left">Perform a range of system administration operations.</td> </tr> <tr> <td style="text-align: left">SYS_BOOT</td> <td style="text-align: left">Use reboot(2) and kexec_load(2), reboot and load a new kernel for later execution.</td> </tr> <tr> <td style="text-align: left">SYS_MODULE</td> <td style="text-align: left">Load and unload kernel modules.</td> </tr> <tr> <td style="text-align: left">SYS_NICE</td> <td style="text-align: left">Raise process nice value (nice(2), setpriority(2)) and change the nice value for arbitrary processes.</td> </tr> <tr> <td style="text-align: left">SYS_PACCT</td> <td style="text-align: left">Use acct(2), switch process accounting on or off.</td> </tr> <tr> <td style="text-align: left">SYS_PTRACE</td> <td style="text-align: left">Trace arbitrary processes using ptrace(2).</td> </tr> <tr> <td style="text-align: left">SYS_RAWIO</td> <td style="text-align: left">Perform I/O port operations (iopl(2) and ioperm(2)).</td> </tr> <tr> <td style="text-align: left">SYS_RESOURCE</td> <td style="text-align: left">Override resource Limits.</td> </tr> <tr> <td style="text-align: left">SYS_TIME</td> <td style="text-align: left">Set system clock (settimeofday(2), stime(2), adjtimex(2)); set real-time (hardware) clock.</td> </tr> <tr> <td style="text-align: left">SYS_TTY_CONFIG</td> <td style="text-align: left">Use vhangup(2); employ various privileged ioctl(2) operations on virtual terminals.</td> </tr> <tr> <td style="text-align: left">SYSLOG</td> <td style="text-align: left">Perform privileged syslog(2) operations.</td> </tr> <tr> <td style="text-align: left">WAKE_ALARM</td> <td style="text-align: left">Trigger something that will wake up the system.</td> </tr> </tbody> </table> <p>Further reference information is available on the <a href="https://man7.org/linux/man-pages/man7/capabilities.7.html">capabilities(7) - Linux man page</a>, and in the <a href="https://github.com/torvalds/linux/blob/124ea650d3072b005457faed69909221c2905a1f/include/uapi/linux/capability.h">Linux kernel source code</a>.</p> <p>Both flags support the value <code class="language-plaintext highlighter-rouge">ALL</code>, so to allow a container to use all capabilities except for <code class="language-plaintext highlighter-rouge">MKNOD</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --cap-add=ALL --cap-drop=MKNOD ...
+</pre></div> <p>The <code class="language-plaintext highlighter-rouge">--cap-add</code> and <code class="language-plaintext highlighter-rouge">--cap-drop</code> flags accept capabilities to be specified with a <code class="language-plaintext highlighter-rouge">CAP_</code> prefix. The following examples are therefore equivalent:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --cap-add=SYS_ADMIN ...
+$ docker run --cap-add=CAP_SYS_ADMIN ...
+</pre></div> <p>For interacting with the network stack, instead of using <code class="language-plaintext highlighter-rouge">--privileged</code> they should use <code class="language-plaintext highlighter-rouge">--cap-add=NET_ADMIN</code> to modify the network interfaces.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --rm ubuntu:14.04 ip link add dummy0 type dummy
+
+RTNETLINK answers: Operation not permitted
+
+$ docker run -it --rm --cap-add=NET_ADMIN ubuntu:14.04 ip link add dummy0 type dummy
+</pre></div> <p>To mount a FUSE based filesystem, you need to combine both <code class="language-plaintext highlighter-rouge">--cap-add</code> and <code class="language-plaintext highlighter-rouge">--device</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --rm -it --cap-add SYS_ADMIN sshfs sshfs sven@10.10.10.20:/home/sven /mnt
+
+fuse: failed to open /dev/fuse: Operation not permitted
+
+$ docker run --rm -it --device /dev/fuse sshfs sshfs sven@10.10.10.20:/home/sven /mnt
+
+fusermount: mount failed: Operation not permitted
+
+$ docker run --rm -it --cap-add SYS_ADMIN --device /dev/fuse sshfs
+
+# sshfs sven@10.10.10.20:/home/sven /mnt
+The authenticity of host '10.10.10.20 (10.10.10.20)' can't be established.
+ECDSA key fingerprint is 25:34:85:75:25:b0:17:46:05:19:04:93:b5:dd:5f:c6.
+Are you sure you want to continue connecting (yes/no)? yes
+sven@10.10.10.20's password:
+
+root@30aa0cfaf1b5:/# ls -la /mnt/src/docker
+
+total 1516
+drwxrwxr-x 1 1000 1000 4096 Dec 4 06:08 .
+drwxrwxr-x 1 1000 1000 4096 Dec 4 11:46 ..
+-rw-rw-r-- 1 1000 1000 16 Oct 8 00:09 .dockerignore
+-rwxrwxr-x 1 1000 1000 464 Oct 8 00:09 .drone.yml
+drwxrwxr-x 1 1000 1000 4096 Dec 4 06:11 .git
+-rw-rw-r-- 1 1000 1000 461 Dec 4 06:08 .gitignore
+....
+</pre></div> <p>The default seccomp profile will adjust to the selected capabilities, in order to allow use of facilities allowed by the capabilities, so you should not have to adjust this.</p> <h2 id="logging-drivers---log-driver">Logging drivers (--log-driver)</h2> <p>The container can have a different logging driver than the Docker daemon. Use the <code class="language-plaintext highlighter-rouge">--log-driver=VALUE</code> with the <code class="language-plaintext highlighter-rouge">docker run</code> command to configure the container’s logging driver. The following options are supported:</p> <table> <thead> <tr> <th style="text-align: left">Driver</th> <th style="text-align: left">Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">none</code></td> <td style="text-align: left">Disables any logging for the container. <code class="language-plaintext highlighter-rouge">docker logs</code> won’t be available with this driver.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">local</code></td> <td style="text-align: left">Logs are stored in a custom format designed for minimal overhead.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">json-file</code></td> <td style="text-align: left">Default logging driver for Docker. Writes JSON messages to file. No logging options are supported for this driver.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">syslog</code></td> <td style="text-align: left">Syslog logging driver for Docker. Writes log messages to syslog.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">journald</code></td> <td style="text-align: left">Journald logging driver for Docker. Writes log messages to <code class="language-plaintext highlighter-rouge">journald</code>.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">gelf</code></td> <td style="text-align: left">Graylog Extended Log Format (GELF) logging driver for Docker. Writes log messages to a GELF endpoint likeGraylog or Logstash.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">fluentd</code></td> <td style="text-align: left">Fluentd logging driver for Docker. Writes log messages to <code class="language-plaintext highlighter-rouge">fluentd</code> (forward input).</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">awslogs</code></td> <td style="text-align: left">Amazon CloudWatch Logs logging driver for Docker. Writes log messages to Amazon CloudWatch Logs.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">splunk</code></td> <td style="text-align: left">Splunk logging driver for Docker. Writes log messages to <code class="language-plaintext highlighter-rouge">splunk</code> using Event Http Collector.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">etwlogs</code></td> <td style="text-align: left">Event Tracing for Windows (ETW) events. Writes log messages as Event Tracing for Windows (ETW) events. Only Windows platforms.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">gcplogs</code></td> <td style="text-align: left">Google Cloud Platform (GCP) Logging. Writes log messages to Google Cloud Platform (GCP) Logging.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">logentries</code></td> <td style="text-align: left">Rapid7 Logentries. Writes log messages to Rapid7 Logentries.</td> </tr> </tbody> </table> <p>The <code class="language-plaintext highlighter-rouge">docker logs</code> command is available only for the <code class="language-plaintext highlighter-rouge">json-file</code> and <code class="language-plaintext highlighter-rouge">journald</code> logging drivers. For detailed information on working with logging drivers, see <a href="https://docs.docker.com/config/containers/logging/configure/">Configure logging drivers</a>.</p> <h2 id="overriding-dockerfile-image-defaults">Overriding Dockerfile image defaults</h2> <p>When a developer builds an image from a <a href="../builder/index"><em>Dockerfile</em></a> or when she commits it, the developer can set a number of default parameters that take effect when the image starts up as a container.</p> <p>Four of the Dockerfile commands cannot be overridden at runtime: <code class="language-plaintext highlighter-rouge">FROM</code>, <code class="language-plaintext highlighter-rouge">MAINTAINER</code>, <code class="language-plaintext highlighter-rouge">RUN</code>, and <code class="language-plaintext highlighter-rouge">ADD</code>. Everything else has a corresponding override in <code class="language-plaintext highlighter-rouge">docker run</code>. We’ll go through what the developer might have set in each Dockerfile instruction and how the operator can override that setting.</p> <ul> <li><a href="#cmd-default-command-or-options">CMD (Default Command or Options)</a></li> <li><a href="#entrypoint-default-command-to-execute-at-runtime">ENTRYPOINT (Default Command to Execute at Runtime)</a></li> <li><a href="#expose-incoming-ports">EXPOSE (Incoming Ports)</a></li> <li><a href="#env-environment-variables">ENV (Environment Variables)</a></li> <li><a href="#healthcheck">HEALTHCHECK</a></li> <li><a href="#volume-shared-filesystems">VOLUME (Shared Filesystems)</a></li> <li><a href="#user">USER</a></li> <li><a href="#workdir">WORKDIR</a></li> </ul> <h3 id="cmd-default-command-or-options">CMD (default command or options)</h3> <p>Recall the optional <code class="language-plaintext highlighter-rouge">COMMAND</code> in the Docker commandline:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
+</pre></div> <p>This command is optional because the person who created the <code class="language-plaintext highlighter-rouge">IMAGE</code> may have already provided a default <code class="language-plaintext highlighter-rouge">COMMAND</code> using the Dockerfile <code class="language-plaintext highlighter-rouge">CMD</code> instruction. As the operator (the person running a container from the image), you can override that <code class="language-plaintext highlighter-rouge">CMD</code> instruction just by specifying a new <code class="language-plaintext highlighter-rouge">COMMAND</code>.</p> <p>If the image also specifies an <code class="language-plaintext highlighter-rouge">ENTRYPOINT</code> then the <code class="language-plaintext highlighter-rouge">CMD</code> or <code class="language-plaintext highlighter-rouge">COMMAND</code> get appended as arguments to the <code class="language-plaintext highlighter-rouge">ENTRYPOINT</code>.</p> <h3 id="entrypoint-default-command-to-execute-at-runtime">ENTRYPOINT (default command to execute at runtime)</h3> <div class="highlight"><pre class="highlight" data-language=""> --entrypoint="": Overwrite the default entrypoint set by the image
+</pre></div> <p>The <code class="language-plaintext highlighter-rouge">ENTRYPOINT</code> of an image is similar to a <code class="language-plaintext highlighter-rouge">COMMAND</code> because it specifies what executable to run when the container starts, but it is (purposely) more difficult to override. The <code class="language-plaintext highlighter-rouge">ENTRYPOINT</code> gives a container its default nature or behavior, so that when you set an <code class="language-plaintext highlighter-rouge">ENTRYPOINT</code> you can run the container <em>as if it were that binary</em>, complete with default options, and you can pass in more options via the <code class="language-plaintext highlighter-rouge">COMMAND</code>. But, sometimes an operator may want to run something else inside the container, so you can override the default <code class="language-plaintext highlighter-rouge">ENTRYPOINT</code> at runtime by using a string to specify the new <code class="language-plaintext highlighter-rouge">ENTRYPOINT</code>. Here is an example of how to run a shell in a container that has been set up to automatically run something else (like <code class="language-plaintext highlighter-rouge">/usr/bin/redis-server</code>):</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --entrypoint /bin/bash example/redis
+</pre></div> <p>or two examples of how to pass more parameters to that ENTRYPOINT:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --entrypoint /bin/bash example/redis -c ls -l
+$ docker run -it --entrypoint /usr/bin/redis-cli example/redis --help
+</pre></div> <p>You can reset a containers entrypoint by passing an empty string, for example:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --entrypoint="" mysql bash
+</pre></div> <blockquote> <p><strong>Note</strong></p> <p>Passing <code class="language-plaintext highlighter-rouge">--entrypoint</code> will clear out any default command set on the image (i.e. any <code class="language-plaintext highlighter-rouge">CMD</code> instruction in the Dockerfile used to build it).</p> </blockquote> <h3 id="expose-incoming-ports">EXPOSE (incoming ports)</h3> <p>The following <code class="language-plaintext highlighter-rouge">run</code> command options work with container networking:</p> <div class="highlight"><pre class="highlight" data-language="">--expose=[]: Expose a port or a range of ports inside the container.
+ These are additional to those exposed by the `EXPOSE` instruction
+-P : Publish all exposed ports to the host interfaces
+-p=[] : Publish a container's port or a range of ports to the host
+ format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
+ Both hostPort and containerPort can be specified as a
+ range of ports. When specifying ranges for both, the
+ number of container ports in the range must match the
+ number of host ports in the range, for example:
+ -p 1234-1236:1234-1236/tcp
+
+ When specifying a range for hostPort only, the
+ containerPort must not be a range. In this case the
+ container port is published somewhere within the
+ specified hostPort range. (e.g., `-p 1234-1236:1234/tcp`)
+
+ (use 'docker port' to see the actual mapping)
+
+--link="" : Add link to another container (&lt;name or id&gt;:alias or &lt;name or id&gt;)
+</pre></div> <p>With the exception of the <code class="language-plaintext highlighter-rouge">EXPOSE</code> directive, an image developer hasn’t got much control over networking. The <code class="language-plaintext highlighter-rouge">EXPOSE</code> instruction defines the initial incoming ports that provide services. These ports are available to processes inside the container. An operator can use the <code class="language-plaintext highlighter-rouge">--expose</code> option to add to the exposed ports.</p> <p>To expose a container’s internal port, an operator can start the container with the <code class="language-plaintext highlighter-rouge">-P</code> or <code class="language-plaintext highlighter-rouge">-p</code> flag. The exposed port is accessible on the host and the ports are available to any client that can reach the host.</p> <p>The <code class="language-plaintext highlighter-rouge">-P</code> option publishes all the ports to the host interfaces. Docker binds each exposed port to a random port on the host. The range of ports are within an <em>ephemeral port range</em> defined by <code class="language-plaintext highlighter-rouge">/proc/sys/net/ipv4/ip_local_port_range</code>. Use the <code class="language-plaintext highlighter-rouge">-p</code> flag to explicitly map a single port or range of ports.</p> <p>The port number inside the container (where the service listens) does not need to match the port number exposed on the outside of the container (where clients connect). For example, inside the container an HTTP service is listening on port 80 (and so the image developer specifies <code class="language-plaintext highlighter-rouge">EXPOSE 80</code> in the Dockerfile). At runtime, the port might be bound to 42800 on the host. To find the mapping between the host ports and the exposed ports, use <code class="language-plaintext highlighter-rouge">docker port</code>.</p> <p>If the operator uses <code class="language-plaintext highlighter-rouge">--link</code> when starting a new client container in the default bridge network, then the client container can access the exposed port via a private networking interface. If <code class="language-plaintext highlighter-rouge">--link</code> is used when starting a container in a user-defined network as described in <a href="https://docs.docker.com/network/"><em>Networking overview</em></a>, it will provide a named alias for the container being linked to.</p> <h3 id="env-environment-variables">ENV (environment variables)</h3> <p>Docker automatically sets some environment variables when creating a Linux container. Docker does not set any environment variables when creating a Windows container.</p> <p>The following environment variables are set for Linux containers:</p> <table> <thead> <tr> <th style="text-align: left">Variable</th> <th style="text-align: left">Value</th> </tr> </thead> <tbody> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">HOME</code></td> <td style="text-align: left">Set based on the value of <code class="language-plaintext highlighter-rouge">USER</code>
+</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">HOSTNAME</code></td> <td style="text-align: left">The hostname associated with the container</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">PATH</code></td> <td style="text-align: left">Includes popular directories, such as <code class="language-plaintext highlighter-rouge">/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin</code>
+</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">TERM</code></td> <td style="text-align: left">
+<code class="language-plaintext highlighter-rouge">xterm</code> if the container is allocated a pseudo-TTY</td> </tr> </tbody> </table> <p>Additionally, the operator can <strong>set any environment variable</strong> in the container by using one or more <code class="language-plaintext highlighter-rouge">-e</code> flags, even overriding those mentioned above, or already defined by the developer with a Dockerfile <code class="language-plaintext highlighter-rouge">ENV</code>. If the operator names an environment variable without specifying a value, then the current value of the named variable is propagated into the container’s environment:</p> <div class="highlight"><pre class="highlight" data-language="">$ export today=Wednesday
+$ docker run -e "deep=purple" -e today --rm alpine env
+
+PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+HOSTNAME=d2219b854598
+deep=purple
+today=Wednesday
+HOME=/root
+</pre></div> <div class="highlight"><pre class="highlight" data-language="">PS C:\&gt; docker run --rm -e "foo=bar" microsoft/nanoserver cmd /s /c set
+ALLUSERSPROFILE=C:\ProgramData
+APPDATA=C:\Users\ContainerAdministrator\AppData\Roaming
+CommonProgramFiles=C:\Program Files\Common Files
+CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
+CommonProgramW6432=C:\Program Files\Common Files
+COMPUTERNAME=C2FAEFCC8253
+ComSpec=C:\Windows\system32\cmd.exe
+foo=bar
+LOCALAPPDATA=C:\Users\ContainerAdministrator\AppData\Local
+NUMBER_OF_PROCESSORS=8
+OS=Windows_NT
+Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Users\ContainerAdministrator\AppData\Local\Microsoft\WindowsApps
+PATHEXT=.COM;.EXE;.BAT;.CMD
+PROCESSOR_ARCHITECTURE=AMD64
+PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 62 Stepping 4, GenuineIntel
+PROCESSOR_LEVEL=6
+PROCESSOR_REVISION=3e04
+ProgramData=C:\ProgramData
+ProgramFiles=C:\Program Files
+ProgramFiles(x86)=C:\Program Files (x86)
+ProgramW6432=C:\Program Files
+PROMPT=$P$G
+PUBLIC=C:\Users\Public
+SystemDrive=C:
+SystemRoot=C:\Windows
+TEMP=C:\Users\ContainerAdministrator\AppData\Local\Temp
+TMP=C:\Users\ContainerAdministrator\AppData\Local\Temp
+USERDOMAIN=User Manager
+USERNAME=ContainerAdministrator
+USERPROFILE=C:\Users\ContainerAdministrator
+windir=C:\Windows
+</pre></div> <p>Similarly the operator can set the <strong>HOSTNAME</strong> (Linux) or <strong>COMPUTERNAME</strong> (Windows) with <code class="language-plaintext highlighter-rouge">-h</code>.</p> <h3 id="healthcheck">HEALTHCHECK</h3> <div class="highlight"><pre class="highlight" data-language=""> --health-cmd Command to run to check health
+ --health-interval Time between running the check
+ --health-retries Consecutive failures needed to report unhealthy
+ --health-timeout Maximum time to allow one check to run
+ --health-start-period Start period for the container to initialize before starting health-retries countdown
+ --no-healthcheck Disable any container-specified HEALTHCHECK
+</pre></div> <p>Example:</p> <div class="highlight"><pre class="highlight" data-language="">
+$ docker run --name=test -d \
+ --health-cmd='stat /etc/passwd || exit 1' \
+ --health-interval=2s \
+ busybox sleep 1d
+$ sleep 2; docker inspect --format='{{.State.Health.Status}}' test
+healthy
+$ docker exec test rm /etc/passwd
+$ sleep 2; docker inspect --format='{{json .State.Health}}' test
+{
+ "Status": "unhealthy",
+ "FailingStreak": 3,
+ "Log": [
+ {
+ "Start": "2016-05-25T17:22:04.635478668Z",
+ "End": "2016-05-25T17:22:04.7272552Z",
+ "ExitCode": 0,
+ "Output": " File: /etc/passwd\n Size: 334 \tBlocks: 8 IO Block: 4096 regular file\nDevice: 32h/50d\tInode: 12 Links: 1\nAccess: (0664/-rw-rw-r--) Uid: ( 0/ root) Gid: ( 0/ root)\nAccess: 2015-12-05 22:05:32.000000000\nModify: 2015..."
+ },
+ {
+ "Start": "2016-05-25T17:22:06.732900633Z",
+ "End": "2016-05-25T17:22:06.822168935Z",
+ "ExitCode": 0,
+ "Output": " File: /etc/passwd\n Size: 334 \tBlocks: 8 IO Block: 4096 regular file\nDevice: 32h/50d\tInode: 12 Links: 1\nAccess: (0664/-rw-rw-r--) Uid: ( 0/ root) Gid: ( 0/ root)\nAccess: 2015-12-05 22:05:32.000000000\nModify: 2015..."
+ },
+ {
+ "Start": "2016-05-25T17:22:08.823956535Z",
+ "End": "2016-05-25T17:22:08.897359124Z",
+ "ExitCode": 1,
+ "Output": "stat: can't stat '/etc/passwd': No such file or directory\n"
+ },
+ {
+ "Start": "2016-05-25T17:22:10.898802931Z",
+ "End": "2016-05-25T17:22:10.969631866Z",
+ "ExitCode": 1,
+ "Output": "stat: can't stat '/etc/passwd': No such file or directory\n"
+ },
+ {
+ "Start": "2016-05-25T17:22:12.971033523Z",
+ "End": "2016-05-25T17:22:13.082015516Z",
+ "ExitCode": 1,
+ "Output": "stat: can't stat '/etc/passwd': No such file or directory\n"
+ }
+ ]
+}
+
+</pre></div> <p>The health status is also displayed in the <code class="language-plaintext highlighter-rouge">docker ps</code> output.</p> <h3 id="tmpfs-mount-tmpfs-filesystems">TMPFS (mount tmpfs filesystems)</h3> <div class="highlight"><pre class="highlight" data-language="">--tmpfs=[]: Create a tmpfs mount with: container-dir[:&lt;options&gt;],
+ where the options are identical to the Linux
+ 'mount -t tmpfs -o' command.
+</pre></div> <p>The example below mounts an empty tmpfs into the container with the <code class="language-plaintext highlighter-rouge">rw</code>, <code class="language-plaintext highlighter-rouge">noexec</code>, <code class="language-plaintext highlighter-rouge">nosuid</code>, and <code class="language-plaintext highlighter-rouge">size=65536k</code> options.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -d --tmpfs /run:rw,noexec,nosuid,size=65536k my_image
+</pre></div> <h3 id="volume-shared-filesystems">VOLUME (shared filesystems)</h3> <div class="highlight"><pre class="highlight" data-language="">-v, --volume=[host-src:]container-dest[:&lt;options&gt;]: Bind mount a volume.
+The comma-delimited `options` are [rw|ro], [z|Z],
+[[r]shared|[r]slave|[r]private], and [nocopy].
+The 'host-src' is an absolute path or a name value.
+
+If neither 'rw' or 'ro' is specified then the volume is mounted in
+read-write mode.
+
+The `nocopy` mode is used to disable automatically copying the requested volume
+path in the container to the volume storage location.
+For named volumes, `copy` is the default mode. Copy modes are not supported
+for bind-mounted volumes.
+
+--volumes-from="": Mount all volumes from the given container(s)
+</pre></div> <blockquote> <p><strong>Note</strong></p> <p>When using systemd to manage the Docker daemon’s start and stop, in the systemd unit file there is an option to control mount propagation for the Docker daemon itself, called <code class="language-plaintext highlighter-rouge">MountFlags</code>. The value of this setting may cause Docker to not see mount propagation changes made on the mount point. For example, if this value is <code class="language-plaintext highlighter-rouge">slave</code>, you may not be able to use the <code class="language-plaintext highlighter-rouge">shared</code> or <code class="language-plaintext highlighter-rouge">rshared</code> propagation on a volume.</p> </blockquote> <p>The volumes commands are complex enough to have their own documentation in section <a href="https://docs.docker.com/storage/volumes/"><em>Use volumes</em></a>. A developer can define one or more <code class="language-plaintext highlighter-rouge">VOLUME</code>’s associated with an image, but only the operator can give access from one container to another (or from a container to a volume mounted on the host).</p> <p>The <code class="language-plaintext highlighter-rouge">container-dest</code> must always be an absolute path such as <code class="language-plaintext highlighter-rouge">/src/docs</code>. The <code class="language-plaintext highlighter-rouge">host-src</code> can either be an absolute path or a <code class="language-plaintext highlighter-rouge">name</code> value. If you supply an absolute path for the <code class="language-plaintext highlighter-rouge">host-src</code>, Docker bind-mounts to the path you specify. If you supply a <code class="language-plaintext highlighter-rouge">name</code>, Docker creates a named volume by that <code class="language-plaintext highlighter-rouge">name</code>.</p> <p>A <code class="language-plaintext highlighter-rouge">name</code> value must start with an alphanumeric character, followed by <code class="language-plaintext highlighter-rouge">a-z0-9</code>, <code class="language-plaintext highlighter-rouge">_</code> (underscore), <code class="language-plaintext highlighter-rouge">.</code> (period) or <code class="language-plaintext highlighter-rouge">-</code> (hyphen). An absolute path starts with a <code class="language-plaintext highlighter-rouge">/</code> (forward slash).</p> <p>For example, you can specify either <code class="language-plaintext highlighter-rouge">/foo</code> or <code class="language-plaintext highlighter-rouge">foo</code> for a <code class="language-plaintext highlighter-rouge">host-src</code> value. If you supply the <code class="language-plaintext highlighter-rouge">/foo</code> value, Docker creates a bind mount. If you supply the <code class="language-plaintext highlighter-rouge">foo</code> specification, Docker creates a named volume.</p> <h3 id="user">USER</h3> <p><code class="language-plaintext highlighter-rouge">root</code> (id = 0) is the default user within a container. The image developer can create additional users. Those users are accessible by name. When passing a numeric ID, the user does not have to exist in the container.</p> <p>The developer can set a default user to run the first process with the Dockerfile <code class="language-plaintext highlighter-rouge">USER</code> instruction. When starting a container, the operator can override the <code class="language-plaintext highlighter-rouge">USER</code> instruction by passing the <code class="language-plaintext highlighter-rouge">-u</code> option.</p> <div class="highlight"><pre class="highlight" data-language="">-u="", --user="": Sets the username or UID used and optionally the groupname or GID for the specified command.
+
+The followings examples are all valid:
+--user=[ user | user:group | uid | uid:gid | user:gid | uid:group ]
+</pre></div> <blockquote> <p><strong>Note:</strong> if you pass a numeric uid, it must be in the range of 0-2147483647.</p> </blockquote> <h3 id="workdir">WORKDIR</h3> <p>The default working directory for running binaries within a container is the root directory (<code class="language-plaintext highlighter-rouge">/</code>). It is possible to set a different working directory with the Dockerfile <code class="language-plaintext highlighter-rouge">WORKDIR</code> command. The operator can override this with:</p> <div class="highlight"><pre class="highlight" data-language="">-w="", --workdir="": Working directory inside the container
+</pre></div>
+<p><a href="https://docs.docker.com/search/?q=docker">docker</a>, <a href="https://docs.docker.com/search/?q=run">run</a>, <a href="https://docs.docker.com/search/?q=configure">configure</a>, <a href="https://docs.docker.com/search/?q=runtime">runtime</a></p>
+<div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2019 Docker, Inc.<br>Licensed under the Apache License, Version 2.0.<br>Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.<br>Docker, Inc. and other parties may also have trademark rights in other terms used herein.<br>
+ <a href="https://docs.docker.com/engine/reference/run/" class="_attribution-link">https://docs.docker.com/engine/reference/run/</a>
+ </p>
+</div>