diff options
Diffstat (limited to 'devdocs/docker/engine%2Freference%2Fcommandline%2Fattach%2Findex.html')
| -rw-r--r-- | devdocs/docker/engine%2Freference%2Fcommandline%2Fattach%2Findex.html | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/devdocs/docker/engine%2Freference%2Fcommandline%2Fattach%2Findex.html b/devdocs/docker/engine%2Freference%2Fcommandline%2Fattach%2Findex.html new file mode 100644 index 00000000..12a221c7 --- /dev/null +++ b/devdocs/docker/engine%2Freference%2Fcommandline%2Fattach%2Findex.html @@ -0,0 +1,65 @@ +<h1>docker attach</h1> <p><br></p> <p>Attach local standard input, output, and error streams to a running container</p> <h2 id="usage">Usage</h2> <div class="highlight"><pre class="highlight" data-language="">$ docker attach [OPTIONS] CONTAINER +</pre></div> <p>Refer to the <a href="#options">options section</a> for an overview of available <a href="#options"><code class="language-plaintext highlighter-rouge">OPTIONS</code></a> for this command.</p> <h2 id="description">Description</h2> <p name="extended-description">Use <code class="language-plaintext highlighter-rouge">docker attach</code> to attach your terminal’s standard input, output, and error (or any combination of the three) to a running container using the container’s ID or name. This allows you to view its ongoing output or to control it interactively, as though the commands were running directly in your terminal.</p> <blockquote> <p><strong>Note:</strong> The <code class="language-plaintext highlighter-rouge">attach</code> command will display the output of the <code class="language-plaintext highlighter-rouge">ENTRYPOINT/CMD</code> process. This can appear as if the attach command is hung when in fact the process may simply not be interacting with the terminal at that time.</p> </blockquote> <p>You can attach to the same contained process multiple times simultaneously, from different sessions on the Docker host.</p> <p>To stop a container, use <code class="language-plaintext highlighter-rouge">CTRL-c</code>. This key sequence sends <code class="language-plaintext highlighter-rouge">SIGKILL</code> to the container. If <code class="language-plaintext highlighter-rouge">--sig-proxy</code> is true (the default),<code class="language-plaintext highlighter-rouge">CTRL-c</code> sends a <code class="language-plaintext highlighter-rouge">SIGINT</code> to the container. If the container was run with <code class="language-plaintext highlighter-rouge">-i</code> and <code class="language-plaintext highlighter-rouge">-t</code>, you can detach from a container and leave it running using the <code class="language-plaintext highlighter-rouge">CTRL-p CTRL-q</code> key sequence.</p> <blockquote> <p><strong>Note:</strong> A process running as PID 1 inside a container is treated specially by Linux: it ignores any signal with the default action. So, 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> <p>It is forbidden to redirect the standard input of a <code class="language-plaintext highlighter-rouge">docker attach</code> command while attaching to a tty-enabled container (i.e.: launched with <code class="language-plaintext highlighter-rouge">-t</code>).</p> <p>While a client is connected to container’s stdio using <code class="language-plaintext highlighter-rouge">docker attach</code>, Docker uses a ~1MB memory buffer to maximize the throughput of the application. If this buffer is filled, the speed of the API connection will start to have an effect on the process output writing speed. This is similar to other applications like SSH. Because of this, it is not recommended to run performance critical applications that generate a lot of output in the foreground over a slow client connection. Instead, users should use the <code class="language-plaintext highlighter-rouge">docker logs</code> command to get access to the logs.</p> <h3 id="override-the-detach-sequence">Override the detach sequence</h3> <p>If you want, you can configure an override the Docker key sequence for detach. This is useful if the Docker default sequence conflicts with key sequence you use for other applications. There are two ways to define your own detach key sequence, as a per-container override or as a configuration property on your entire configuration.</p> <p>To override the sequence for an individual container, use the <code class="language-plaintext highlighter-rouge">--detach-keys="<sequence>"</code> flag with the <code class="language-plaintext highlighter-rouge">docker attach</code> command. The format of the <code class="language-plaintext highlighter-rouge"><sequence></code> is either a letter [a-Z], or the <code class="language-plaintext highlighter-rouge">ctrl-</code> combined with any of the following:</p> <ul> <li> +<code class="language-plaintext highlighter-rouge">a-z</code> (a single lowercase alpha character )</li> <li> +<code class="language-plaintext highlighter-rouge">@</code> (at sign)</li> <li> +<code class="language-plaintext highlighter-rouge">[</code> (left bracket)</li> <li> +<code class="language-plaintext highlighter-rouge">\\</code> (two backward slashes)</li> <li> +<code class="language-plaintext highlighter-rouge">_</code> (underscore)</li> <li> +<code class="language-plaintext highlighter-rouge">^</code> (caret)</li> </ul> <p>These <code class="language-plaintext highlighter-rouge">a</code>, <code class="language-plaintext highlighter-rouge">ctrl-a</code>, <code class="language-plaintext highlighter-rouge">X</code>, or <code class="language-plaintext highlighter-rouge">ctrl-\\</code> values are all examples of valid key sequences. To configure a different configuration default key sequence for all containers, see <a href="../cli/index#configuration-files"><strong>Configuration file</strong> section</a>.</p> <p>For example uses of this command, refer to the <a href="#examples">examples section</a> below.</p> <h2 id="options">Options</h2> <table> <thead> <tr> <td>Name, shorthand</td> <td>Default</td> <td>Description</td> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">--detach-keys</code></td> <td></td> <td>Override the key sequence for detaching a container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--no-stdin</code></td> <td></td> <td>Do not attach STDIN</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--sig-proxy</code></td> <td><code class="language-plaintext highlighter-rouge">true</code></td> <td>Proxy all received signals to the process</td> </tr> </tbody> </table> <h2 id="examples">Examples</h2> <h3 id="attach-to-and-detach-from-a-running-container">Attach to and detach from a running container</h3> <div class="highlight"><pre class="highlight" data-language="">$ docker run -d --name topdemo ubuntu /usr/bin/top -b + +$ docker attach topdemo + +top - 02:05:52 up 3:05, 0 users, load average: 0.01, 0.02, 0.05 +Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie +Cpu(s): 0.1%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st +Mem: 373572k total, 355560k used, 18012k free, 27872k buffers +Swap: 786428k total, 0k used, 786428k free, 221740k cached + +PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND + 1 root 20 0 17200 1116 912 R 0 0.3 0:00.03 top + + top - 02:05:55 up 3:05, 0 users, load average: 0.01, 0.02, 0.05 + Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie + Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st + Mem: 373572k total, 355244k used, 18328k free, 27872k buffers + Swap: 786428k total, 0k used, 786428k free, 221776k cached + + PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND + 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top + + + top - 02:05:58 up 3:06, 0 users, load average: 0.01, 0.02, 0.05 + Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie + Cpu(s): 0.2%us, 0.3%sy, 0.0%ni, 99.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st + Mem: 373572k total, 355780k used, 17792k free, 27880k buffers + Swap: 786428k total, 0k used, 786428k free, 221776k cached + + PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND + 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top +^C$ + +$ echo $? +0 +$ docker ps -a | grep topdemo + +7998ac8581f9 ubuntu:14.04 "/usr/bin/top -b" 38 seconds ago Exited (0) 21 seconds ago topdemo +</pre></div> <h3 id="get-the-exit-code-of-the-containers-command">Get the exit code of the container’s command</h3> <p>And in this second example, you can see the exit code returned by the <code class="language-plaintext highlighter-rouge">bash</code> process is returned by the <code class="language-plaintext highlighter-rouge">docker attach</code> command to its caller too:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --name test -d -it debian +275c44472aebd77c926d4527885bb09f2f6db21d878c75f0a1c212c03d3bcfab + +$ docker attach test +root@f38c87f2a42d:/# exit 13 + +exit + +$ echo $? +13 + +$ docker ps -a | grep test + +275c44472aeb debian:7 "/bin/bash" 26 seconds ago Exited (13) 17 seconds ago test +</pre></div> <div class="_attribution"> + <p class="_attribution-p"> + © 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/commandline/attach/" class="_attribution-link">https://docs.docker.com/engine/reference/commandline/attach/</a> + </p> +</div> |
