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?
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?
to stop a docker process and release the ports, first use ctrl-c to leave the exit the container then use docker ps to find the list of running containers. Then you can use the docker container stop to stop that process and release its ports. The container name you can find from the docker ps command which gives the name in the name column. Hope this solves your queries....
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
^c
directly, it won't affect the original process.To detach from a running container, use ^P^Q (hold the Ctrl, press P, press Q, release Ctrl).
There's a catch: this only works if the container was started with both
-t
and-i
.If you have a running container that was started without one (or both) of these options, and you attach with
docker attach
, you'll need to find another way to detach. Depending on the options you chose and the program that's running, ^C may work, or it may kill the whole container. You'll have to experiment.Another catch: Depending on the programs you're using, your terminal, shell, SSH client, or multiplexer could be intercepting either ^P or ^Q (usually the latter). To test whether this is the issue, try running or attaching with the
--detach-keys z
argument. You should now be able to detach by pressing z, without any modifiers. If this works, another program is interfering. The easiest way to work around this is to set your own detach sequence using the--detach-keys
argument. (For example, to exit with ^K, use--detach-keys 'ctrl-k'
.) Alternatively, you can attempt to disable interception of the keys in your terminal or other interfering program. For example,stty start ''
orstty start undef
may prevent the terminal from intercepting ^Q on some POSIX systems, though I haven't found this to be helpful.In the same shell, hold
ctrl
key and press keysp
thenq