我可以附加到一个docker进程,但Ctrl+C不能从它分离。退出基本上停止了进程。
让流程运行,偶尔附加到流程上进行一些更改,然后再分离的推荐工作流是什么?
我可以附加到一个docker进程,但Ctrl+C不能从它分离。退出基本上停止了进程。
让流程运行,偶尔附加到流程上进行一些更改,然后再分离的推荐工作流是什么?
当前回答
如果——sig-proxy=false方法不起作用,那么您还可以使用以下命令更改转义序列:
docker attach --detach-keys="<sequence>" <container_name or id>
例如,我想使用“ctrl-c”分离容器,然后我可以使用以下方法附加容器:
docker attach --detach-keys="ctrl-c" <container_name or id>
的格式可以是字母[a- z],也可以是ctrl-和以下任意组合:
a-z(一个小写字母) @(@号) [(左括号) \(两个反斜杠) _(下划线) ^(脱字符号)
有关更多信息,请参见->覆盖分离序列
其他回答
当没有其他工作,打开一个新的终端然后:
$ ps aux | grep attach
username <pid_here> .............. 0:00 docker attach <CONTAINER_HASH_HERE>
username <another_pid> .............. 0:00 grep --color=auto attach
$ kill -9 <pid_here>
在同一个shell中,按住Ctrl键,然后按P键和Q键
要从正在运行的容器中分离,请使用^P^Q(按住Ctrl,按P,按Q,释放Ctrl)。
这里有一个问题:这只在容器同时以-t和-i开始时才有效。
如果你有一个正在运行的容器,启动时没有这些选项中的一个(或两个),并且你使用docker attach附加,你需要找到另一种方法来分离。^C可以工作,也可以杀死整个容器,这取决于你选择的选项和正在运行的程序。你得自己试验一下。
Another catch: Depending on the programs you're using, your terminal, shell, SSH client, or multiplexer could be intercepting either ^P or ^Q (usually the latter). To test whether this is the issue, try running or attaching with the --detach-keys z argument. You should now be able to detach by pressing z, without any modifiers. If this works, another program is interfering. The easiest way to work around this is to set your own detach sequence using the --detach-keys argument. (For example, to exit with ^K, use --detach-keys 'ctrl-k'.) Alternatively, you can attempt to disable interception of the keys in your terminal or other interfering program. For example, stty start '' or stty start undef may prevent the terminal from intercepting ^Q on some POSIX systems, though I haven't found this to be helpful.
要在不退出shell的情况下分离tty,请使用转义序列Ctrl+P后跟Ctrl+Q。详情请点击这里。
来自此来源的其他信息:
docker run -t -i→可以用^P^ q分离,用docker attach重新连接 docker run -i→不能与^P^Q分离;将中断stdin docker run→不能与^P^Q分离;可以SIGKILL客户端;可以用docker attach重新连接吗
我有同样的问题,Ctrl+P和Q不能工作,也不是Ctrl+C…最终,我打开了另一个终端会话,我做了“docker stop containerid”和“docker start containerid”,它完成了工作。奇怪。