Correct way to detach from a container without sto

2019-01-20 21:33发布

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

So for example, if I try:

  • 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?

exit and CTR+C both stop the container.

标签: docker
9条回答
在下西门庆
2楼-- · 2019-01-20 21:55

I consider Ashwin's answer to be the most correct, my old answer is below.


I'd like to add another option here which is to run the container as follows

docker run -dti foo bash

You can then enter the container and run bash with

docker exec -ti ID_of_foo bash

No need to install sshd :)

查看更多
3楼-- · 2019-01-20 21:56

If you attached through docker attach, you can detach by killing the docker attach process. Better way is to use sig-proxy parameter to avoid passing the Ctrl+C to your container :

docker attach --sig-proxy=false [container-name]

Same option is available for docker run command.

查看更多
叼着烟拽天下
4楼-- · 2019-01-20 22:02

If you just want see the output of the process running from within the container, you can do a simple docker container logs -f <container id>.

The -f flag makes it so that the output of the container is followed and updated in real-time. Very useful for debugging or monitoring.

查看更多
登录 后发表回答