Docker:重新附加到docker exec进程 [英] Docker: reattach to `docker exec` process

查看:170
本文介绍了Docker:重新附加到docker exec进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 docker exec 来启动外壳,

If I use docker exec to fire up a shell,

docker exec -ti <CONTAINER> /bin/bash

我可以使用Ctrl + p Ctrl + q分离此shell进程。然后此shell仍在容器内运行,但是我如何重新附加到该特定shell(由 docker exec 启动的外壳,而不是 docker run )?

I could use Ctrl+p Ctrl+q to detach this shell process. Then this shell is still running inside the container, but how can I reattach to that one particular shell (the one started by docker exec, not docker run)?

推荐答案

可惜的是,这还不可能;请参阅此问题在GitHub上。我也想要此功能,但目前看来尚无直接方法。

Sadly, this is not possible yet; see this issue on GitHub. I've also wanted this functionality, but at the moment it seems like there's no direct way to do this.

已提出解决方案,以解决此问题您通过 ssh 访问一个框并在远程框中运行 docker exec 的位置(或者,对于您的终端仿真器不稳定,可能会导致您崩溃):始终运行您的<$ c $在屏幕 tmux 中使用c> docker exec 命令。这样,只要您脱离屏幕 / tmux 会话,就可以稍后重新连接到该会话,并且仍然您的 docker exec 命令可访问。 (这与建议由@ vodolaz095 有所不同,因为它涉及运行屏幕 tmux 外部容器,所以它适合与不运行屏幕 / tmux 作为其主要过程的容器)

A workaround has been proposed, to take care of the case where you're accessing a box via ssh and running docker exec on the remote box (or, for the case where your terminal emulator is unstable and may crash on you): Always run your docker exec commands inside screen or tmux. If you do this, whenever you get detached from the screen/tmux session, you can re-attach to it later and still have your docker exec commands accessible. (this is a bit different than what was suggested by @vodolaz095, since it involves running screen or tmux outside the container, making it suitable for use with containers that don't run screen/tmux as their main process)

这篇关于Docker:重新附加到docker exec进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆