how to detach from a docker container

Docker

Docker Problem Overview


This problem is quite similar like this, but I am still having problems:

I run a container with:

docker run -d CONTAINER

then I attach to it with

docker attach NAME

but I cannot exit it, not with CTRL-C, nor with CTRL-P + CTRL-Q (like suggested in the similar question above)

I have to kill -9 PID to exit it...

What am I doing wrong?

Info:

Docker version 0.6.7, build cb48ecc
Ubuntu 3.8.0-33-generic #48~precise1-Ubuntu

Docker Solutions


Solution 1 - Docker

As Jérôme Petazzoni mentioned in docker-user group:

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

Solution 2 - Docker

You should attach to the container using the --sig-proxy=false option like this:

docker attach --sig-proxy=false NAME

Then you can use CTRL+Cto exit without stopping the container itself.

Solution 3 - Docker

Attaching with:

docker attach <container name>

allows me to detach with Ctrl+d in Docker version 17.04

I know this is old, but since none of the methods shown above work for me, I thought I'd share.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionintrixiusView Question on Stackoverflow
Solution 1 - DockerFedeView Answer on Stackoverflow
Solution 2 - DockerHans KristianView Answer on Stackoverflow
Solution 3 - DockerverdudeView Answer on Stackoverflow