Red Hat Bugzilla – Bug 1113608
`docker attach` hangs when attaching container, which is exiting
Last modified: 2015-03-04 22:19:04 EST
Description of problem: When you execute `docker attach` on a container, which is in the process of shutting down, the process doesn't fail, but hangs for ever. Even when you remove (`docker rm`) the container afterwards, the process still exists and when you use eg. ctrl+c, it complains about missing container. When you have stdin attached, it finishes after an input, otherwise you have to use `kill -9` to get rid of it. Version-Release number of selected component (if applicable): docker-0.11.1-10.el7.x86_64 docker-io-1.0.0-3.fc20.x86_64 How reproducible: rarely on RHEL7 (0.11.1), always on Fedora 20 (1.0.0-3) Steps to Reproduce: 1. in 1st terminal execute: "while :; do sudo docker -D attach `sudo docker ps -l -q`; done" 2a. in 2nd terminal execute: "docker run -i -t fedora bash" and when the first terminal attaches, use `exit` or `ctrl+d` to stop the container. 2b. when the 2a doesn't causes the bug, use this script to start-stop containers in a loop: "while :; do ID=`docker run -d -i -t fedora bash`; sleep 1; echo exit | docker attach $ID; done" Actual results: On Fedora after step 2a the attach process in 1st terminal hangs, there is no new input. On RHEL after a while while executing the 2b script, the attach process in 1st terminal hangs. Expected results: The attach process in 1st terminal should finish when the container is destroyed and lots of messages like: 2014/06/26 15:29:55 You cannot attach to a stopped container, start it first 2014/06/26 15:29:55 You cannot attach to a stopped container, start it first 2014/06/26 15:29:55 You cannot attach to a stopped container, start it first 2014/06/26 15:29:55 You cannot attach to a stopped container, start it first should occur (as we are trying to attach stopped container). Additional info: When you use `docker attach --no-stdin ...` you can write anything. After a ctrl+c it realizes the container is not running and finishes. ctrl+p+q doesn't work. In RHEL version when you remove the container by `docker rm` first, ctrl+c generates message in docker daemon, that the container with id ... doesn't exist and the `docker attach` process is still hanged. When you have stdin attached, after sending any character the process is destoyed with: [debug] hijack.go:96 [hijack] End of stdout 2014/06/26 15:49:31 You cannot attach to a stopped container, start it first
Upstream found a bug in docker (Caused by a fix from me) blocks interactive terminals from exiting. Might fix this problem.
OK I tried that on F21 with docker-io-1.2.0-2.fc21.x86_64 and it works fine (no failure after couple of hours).
Great,
Fixed in docker-1.2
With docker-1.4.1-27.el7.x86_64, run the script # cat 1113608.sh # /bin/bash while :; do ID=`docker run -d -i -t rhel7 bash`; sleep 1; echo exit | docker attach $ID; done generated FATA[0000] cannot enable tty mode on non tty input FATA[0000] cannot enable tty mode on non tty input no hang here, so move to verify
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://rhn.redhat.com/errata/RHSA-2015-0623.html