I find that docker attach
command only attach to the first tty(pts/0 or PID 1) of a container that has many ttys.
E.g. If I create a container test0
first:
docker run -it --name test0 ubuntu18.04 /bin/bash
Than press ctrl+p,q
, this first bash process will be detached and keep running in the Background.
And than I create a new back-ground shell again by docker exec -it test0 /bin/bash
and pressing ctrl+p,q
again.
Above sequence will create two ttys within container test0
, as listed in docker exec 032 ps -ef
:
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Oct29 pts/0 00:00:00 /bin/bash
root 1491 0 0 00:11 pts/1 00:00:00 /bin/bash
root 1740 0 0 00:59 ? 00:00:00 ps -ef
Every time I try to use docker attach test0
will only result in the attaching to pts/0
which PID is 1. But I still need to do some work under pts/1
or PID 1491. What should I do to attach to the pts/1
which PID is 1491?
BESIDES, I also thought about using tmux or screen within the first tty BUT I wonder if its a good way for docker - docker features in making processes run fast and light-weighted, I don’t know if using tmux to handle processes will slow them down.