I commonly want to open a bash shell on a docker image. A multi-command process for this would be:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bba983d72d48 scubbo/datenight "apachectl -DFOREGROU" 7 days ago Up 7 days 0.0.0.0:80->80/tcp pensive_bell
$ docker exec -it bba983d72d48 bash
I'd like to shortcut this. However, I get the following error:
$ docker ps | awk 'NR > 1 {print $1}' | xargs -I {} docker exec -it {} bash
cannot enable tty mode on non tty input
From a little Googling, I found this issue - however, if I drop the -t
option, the command "completes" immediately.
I have confirmed that manually copy-pasting the output of $ docker ps | awk 'NR > 1 {print $1}'
into the appropriate position of docker exec -it {} bash
is successful.
EDIT: Cutting out the docker ps
from the pipe, the following also fails:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4f20409c37b7 scubbo/datenight "apachectl -DFOREGROU" 8 days ago Up 8 days 0.0.0.0:80->80/tcp drunk_northcutt
$ docker ps -q
4f20409c37b7
$ echo '4f20409c37b7' | xargs -I {} docker exec -it {} bash
cannot enable tty mode on non tty input