Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

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 recommended workflow to have the process running, occasionally attaching to it to make some changes, and then detaching?

like image 354
MarkL Avatar asked Oct 30 '13 16:10

MarkL


People also ask

How do you detach from a container?

Docker supports a keyboard combination to gracefully detach from a container. Press Ctrl-P, followed by Ctrl-Q, to detach from your connection. You'll be dropped back into your shell but the previously attached process will remain alive, keeping your container running.

How do I detach from docker compose up?

By default, a Docker Compose starts the services in the foreground mode just like a docker run command. To run the Docker Compose in the background, a docker-compose up command should be started with the -d or --detach option.

How do you detach the volume of a container?

To remove one or more Docker volumes, run the docker volume ls command to find the ID of the volumes you want to remove. If you get an error similar to the one shown below, it means that an existing container uses the volume. To remove the volume, you will have to remove the container first.


2 Answers

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
like image 156
Ken Cochrane Avatar answered Oct 13 '22 00:10

Ken Cochrane


Check out also the --sig-proxy option:

docker attach --sig-proxy=false 304f5db405ec 

Then use CTRL+c to detach

like image 42
czerasz Avatar answered Oct 12 '22 22:10

czerasz