在不停止容器的情况下从容器中分离的正确方法 [英] Correct way to detach from a container without stopping it

查看:33
本文介绍了在不停止容器的情况下从容器中分离的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Docker 1.1.2(最新)中,在不停止容器的情况下从容器分离的正确方法是什么?

In Docker 1.1.2 (latest), what's the correct way to detach from a container without stopping it?

例如,如果我尝试:

  • docker run -i -t foo/bin/bash
  • docker attach foo(用于已经运行的容器)
  • docker run -i -t foo /bin/bash or
  • docker attach foo (for already running container)

两者都让我到达容器中的终端,我如何在不停止的情况下退出容器的终端?

both of which get me to a terminal in the container, how do I exit the container's terminal without stopping it?

exitCTR+C 都停止容器.

推荐答案

更新: 如以下答案中提到的 Ctrl+p, Ctrl+q 现在将把交互模式变成守护进程模式.

Update: As mentioned in below answers Ctrl+p, Ctrl+q will now turn interactive mode into daemon mode.

好吧 Ctrl+C(或 Ctrl+)应该将您从容器中分离,但是 它会杀死容器因为你的主进程是一个bash.

Well Ctrl+C (or Ctrl+) should detach you from the container but it will kill the container because your main process is a bash.

关于 docker 的一点教训.容器不是真正的全功能操作系统.当您运行容器时,您启动的进程将采用 PID 1 并承担 init 权力.因此,当该进程终止时,守护进程将停止容器,直到启动一个新进程(通过 docker start)(有关此事的更多解释 http://phusion.github.io/baseimage-docker/#intro)

A little lesson about docker. The container is not a real full functional OS. When you run a container the process you launch take the PID 1 and assume init power. So when that process is terminated the daemon stop the container until a new process is launched (via docker start) (More explanation on the matter http://phusion.github.io/baseimage-docker/#intro)

如果你想要一个一直以分离模式运行的容器,我建议你使用

If you want a container that run in detached mode all the time, i suggest you use

docker run -d foo

在容器上有一个 ssh 服务器.(最简单的方法是遵循 dockerizing openssh 教程 https://docs.docker.com/engine/示例/running_ssh_service/)

With an ssh server on the container. (easiest way is to follow the dockerizing openssh tutorial https://docs.docker.com/engine/examples/running_ssh_service/)

或者你可以通过

docker start foo

(默认是分离的)

这篇关于在不停止容器的情况下从容器中分离的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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