If I use docker exec
to fire up a shell,
docker exec -ti <CONTAINER> /bin/bash
I could use Ctrl+p Ctrl+q to detach this shell process. Then this shell is still running inside the container, but how can I reattach to that one particular shell (the one started by docker exec
, not docker run
)?
docker exec
is specifically for running new things in an already started container, be it a shell or some other process.docker attach
is for attaching to a running process, so you can use only one instance of shell.Run you container(process)
Then
To detach Ctrl+p + Ctrl+q
On this way you can attach and detach multiple times with only one instance of shell
Sadly, this is not possible yet; see this issue on GitHub. I've also wanted this functionality, but at the moment it seems like there's no direct way to do this.
A workaround has been proposed, to take care of the case where you're accessing a box via
ssh
and runningdocker exec
on the remote box (or, for the case where your terminal emulator is unstable and may crash on you): Always run yourdocker exec
commands insidescreen
ortmux
. If you do this, whenever you get detached from thescreen
/tmux
session, you can re-attach to it later and still have yourdocker exec
commands accessible. (this is a bit different than what was suggested by @vodolaz095, since it involves runningscreen
ortmux
outside the container, making it suitable for use with containers that don't runscreen
/tmux
as their main process)