Lets say I have a container running and I do
docker exec -ti container-id /bin/bash
Then I detach from this container and want to attach again
If I do this
docker attach container-id
I wont go back to that bash that I created. Instead I will go to the main process.
How can I attach to that bash again ?
I have one container and I have started it using, and checked the pid
of /bin/bash
[root@ip-10-0-1-153 centos]# docker exec -ti 78c2e4a46b58 /bin/bash
root@78c2e4a46b58:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 03:24 ? 00:00:00 bash
root 10 0 0 03:24 ? 00:00:00 /bin/bash
root 20 10 0 03:24 ? 00:00:00 ps -ef
Now I detach from container using CTR+p and CTR+q
sequence and container is detached.
Now I reattach using the container id and I see the same pid
of /bin/bash
root@78c2e4a46b58:/# [root@ip-10-0-1-153 centos]# docker attach 78c2e4a46b58
root@78c2e4a46b58:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 03:24 ? 00:00:00 bash
root 10 0 0 03:24 ? 00:00:00 /bin/bash
root 21 1 0 03:25 ? 00:00:00 ps -ef
root@78c2e4a46b58:/#
I hope you're using CTR+p CTR+q
sequence to detach from the container.
You can't. While the docker exec
documentation suggests it supports the same "detach" key sequence as docker run
, the exec'd process doesn't have any Docker-level identity (beyond its host and container pids) and there's no way to re-attach to that shell.
(In the Docker API, "exec instance" is an actual object so this isn't technically impossible; the CLI just has no support for it.)
The workflow you're describing sounds more like what you'd run with screen
or tmux
in a virtual machine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.