Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detach from a docker container

Tags:

docker

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

like image 910
intrixius Avatar asked Nov 22 '13 13:11

intrixius


People also ask

How do you get out of a container?

Just Stopping the Container If you want to stop and exit the container, and are in an interactive, responsive shell - press ctrl+d to exit the session. You could as well type the exit command. TL;DR: press ctrl+c then ctrl+d - that means, keep the ctrl key pressed, type a c, and let go of ctrl.

How do I leave a docker container?

How do you exit a docker container? This way, you get an interactive shell and you are immediately logged into the OS running as container. To exit from this running container, you can use ctrl+c, ctrl+d or enter exit in the terminal.

How do I detach a docker container Mac?

To stop a container, use CTRL-c . This key sequence sends SIGKILL to the container. If --sig-proxy is true (the default), CTRL-c sends a SIGINT to the container. If the container was run with -i and -t , you can detach from a container and leave it running using the CTRL-p CTRL-q key sequence.

How do you run a container in detach mode?

To start a container in detached mode, you use -d=true or just -d option. By design, containers started in detached mode exit when the root process used to run the container exits, unless you also specify the --rm option.


2 Answers

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 
like image 143
Fede Avatar answered Oct 13 '22 06:10

Fede


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.

like image 33
Hans Kristian Avatar answered Oct 13 '22 07:10

Hans Kristian