uTools-Manuals/docs/docker/docker attach.html
2019-04-21 11:50:48 +08:00

14 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1>Docker attach 命令</h1>
<p><strong>docker attach :</strong>连接到正在运行中的容器。</p>
<h3>语法</h3>
<pre>docker attach [OPTIONS] CONTAINER</pre>
<p>要attach上去的容器必须正在运行可以同时连接上同一个container来共享屏幕与screen命令的attach类似</p><p>
官方文档中说attach后可以通过CTRL-C来detach但实际上经过我的测试如果container当前在运行bashCTRL-C自然是当前行的输入没有退出如果container当前正在前台运行进程如输出nginx的access.log日志CTRL-C不仅会导致退出容器而且还stop了。这不是我们想要的detach的意思按理应该是脱离容器终端但容器依然运行。好在attach是可以带上--sig-proxy=false来确保CTRL-D或CTRL-C不会关闭容器。</p>
<h3>实例</h3>
<p>容器mynginx将访问日志指到标准输出连接到容器查看访问信息。</p>
<pre>runoob@runoob:~$ docker attach --sig-proxy=false mynginx
192.168.239.1 - - [10/Jul/2016:16:54:26 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36" "-"
</pre>