如何从docker容器中分离出来

int*_*ius 51 docker

这个问题是相当类似像这样,但我仍然有问题:

我运行一个容器:

docker run -d CONTAINER
Run Code Online (Sandbox Code Playgroud)

然后我依附于它

docker attach NAME
Run Code Online (Sandbox Code Playgroud)

但是我不能退出它,不能用CTRL-C,也不能用CTRL-P + CTRL-Q(就像上面类似问题中的建议一样)

我必须kill -9 PID退出...

我究竟做错了什么?

信息:

Docker版本0.6.7,构建cb48ecc
Ubuntu 3.8.0-33-通用#48~precision1-Ubuntu

小智 83

正如JérômePetazzoni在docker-user组中提到的那样:

Actually, you can SIGKILL the client, and reattach later.
However, this will disrupt stdin (the container will see EOF on stdin, and if it cares about stdin, e.g. if it's a shell, it will exit).

To recap:
docker run -t -i ? can be detached with ^P^Q and reattached with docker attach
docker run -i ? cannot be detached with ^P^Q; will disrupt stdin
docker run ? cannot be detached with ^P^Q; can SIGKILL client; can reattach with docker attach


Han*_*ian 74

您应该attach使用如下--sig-proxy=false选项访问容器:

docker attach --sig-proxy=false NAME
Run Code Online (Sandbox Code Playgroud)

然后你可以使用CTRL+ C退出而不停止容器本身.

  • 在我的系统中没有真正起作用.使用^ P ^ Q的解决方案完美无缺! (4认同)