如何附加到以分离模式运行的Docker容器? [英] How can I attach to docker container running in detached mode?
问题描述
如果我使用以下命令以分离模式启动Docker容器:
If I start up a docker container in detached mode using the command:
docker run -d ubuntu
容器立即退出。 docker ps -a
产生输出(显示选定的列):
the container immediately exits. docker ps -a
yields the output (selected columns shown):
CONTAINER ID IMAGE COMMAND STATUS
245fe871a1e3 ubuntu "/bin/bash" Exited (0) 4 minutes ago
是否可以在终端会话的交互模式下启动同一容器(容器ID 245fe871a1e3
)?
Is it possible to start the same container (container ID 245fe871a1e3
) in interactive mode with a terminal session?
推荐答案
恐怕没有这样一种存档方法。 docker attach
和 docker exec
仅适用于运行容器,但是如果您 docker start
您所用的容器,由于 CMD
为 / bin / bash $ c $,它会立即再次退出c>。
I'm afraid there's no such a way to archive this. docker attach
and docker exec
are working against running container only, but if you docker start
the container in your case, it'll exited immediately again because the CMD
is /bin/bash
.
还有讨论关于此信息,请在此处发布一些关键信息:
There's also a discussion about this, post some key info here:
不可能输入已停止的容器,因为进程已消失,因此,名称空间也消失了。
It's not possible to enter a stopped container, because the processes are gone, and therefore, the namespaces are gone as well.
这篇关于如何附加到以分离模式运行的Docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!