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

后端 未结 15 801
情书的邮戳
情书的邮戳 2020-11-29 14:42

I can attach to a docker process but Ctrl+c doesn\'t work to detach from it. exit basically halts the process.

What\'s the recomm

相关标签:
15条回答
  • 2020-11-29 14:42

    To detach from the container you simply hold Ctrl and press P + Q.

    To attach to a running container you use:

    $ docker container attach "container_name"
    
    0 讨论(0)
  • 2020-11-29 14:45

    If you only need the docker process to go in the background you can use

    Ctrl + Z

    Be aware that it is not a real detach and it comes with a performance penalty. (You can return it to foreground with the bg command).

    Another option is to just close your terminal, if you don't need it any longer.

    0 讨论(0)
  • 2020-11-29 14:47

    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
    0 讨论(0)
  • 2020-11-29 14:50

    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.

    0 讨论(0)
  • 2020-11-29 14:50
    1. Open a new terminal
    2. Find the running container Id docker ps
    3. Kill the container docker kill ${containerId}
    0 讨论(0)
  • 2020-11-29 14:57

    I'm on a Mac, and for some reason, Ctrl-p Ctrl-q would only work if I also held Shift

    0 讨论(0)
提交回复
热议问题