How do you attach and detach from Docker's process?

To detach the tty without exiting the shell, use the escape sequence Ctrl+P followed by Ctrl+Q. More details here.

Additional info from this source:

  • docker run -t -i → can be detached with ^P^Qand 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

Check out also the --sig-proxy option:

docker attach --sig-proxy=false 304f5db405ec

Then use CTRL+c to detach


If you just want to make some modification to files or inspect processes, here's one another solution you probably want.

You could run the following command to execute a new process from the existing container:

sudo docker exec -ti [CONTAINER-ID] bash

will start a new process with bash shell, and you could escape from it by Ctrl+C directly, it won't affect the original process.

Tags:

Docker