gotty
gotty copied to clipboard
Docker container won't exit by closing browser window
tested on Arch Linux / GoTTY 0.0.12.
I ran:
gotty -w docker run -it --rm busybox
docker ps
at that time:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
after that I opened server:8080:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92a48175bea8 busybox "sh" 4 seconds ago Up 3 seconds silly_lovelace
and close it:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92a48175bea8 busybox "sh" 4 seconds ago Up 3 seconds silly_lovelace
busybox is still there.
here is the log from gotty:
2016/02/01 00:40:17 Permitting clients to write input to the PTY.
2016/02/01 00:40:17 Server is starting with command: docker run -it --rm busybox
2016/02/01 00:40:17 URL: http://127.0.0.1:8080/
2016/02/01 00:40:17 URL: http://[::1]:8080/
2016/02/01 00:40:17 URL: http://192.168.1.47:8080/
2016/02/01 00:40:17 URL: http://[2408:212:48:9000:21d:baff:feab:e766]:8080/
2016/02/01 00:40:17 URL: http://[fe80::21d:baff:feab:e766]:8080/
2016/02/01 00:40:17 URL: http://172.17.0.1:8080/
2016/02/01 00:40:17 URL: http://[fe80::42:6eff:fe0a:9fca]:8080/
2016/02/01 00:45:22 192.168.1.7:55741 200 GET /
2016/02/01 00:45:22 192.168.1.7:55741 200 GET /auth_token.js
2016/02/01 00:45:22 192.168.1.7:55742 200 GET /js/gotty.js
2016/02/01 00:45:22 192.168.1.7:55743 200 GET /js/hterm.js
2016/02/01 00:45:22 New client connected: 192.168.1.7:55744
2016/02/01 00:45:22 Command is running for client 192.168.1.7:55744 with PID 2924 (args="run -it --rm busybox")
2016/02/01 00:45:22 192.168.1.7:55744 101 GET /ws
2016/02/01 00:46:02 websocket: close 1006 unexpected EOF
2016/02/01 00:46:02 Command exited for: 192.168.1.7:55744
2016/02/01 00:46:02 Connection closed: 192.168.1.7:55744
I had the same problem. The docker process is not killed when you detach the interactive shell. I added a few lines after context.pty.Close() in "goHandleClient" to call "docker kill" and "docker rm" to clean up the container.
+1
A workaround to prevent a container from living indefinitely is to add a timeout on the interactive process, so you can be sure the container is always terminated.
MAX_CONTAINER_AGE=30 # seconds
gotty --permit-write docker run --rm -it ubuntu timeout $MAX_CONTAINER_AGE bash
Of course it would be ideal if clients remembered to exit
from the shell before closing the browser window.
I've resolved this issue partially. Now the docker
command, which is just a client, is closed properly by SIGHUP
.
However, docker itself has an issue on the --sig-proxy
option (https://github.com/moby/moby/issues/28872). We need an upstream fix for the ultimate resolution
A workaround to all this would be not to run a docker command with GoTTY but rathern run GoTTY inside a container itself. Here is an example Dockerfile:
FROM golang RUN go get github.com/yudai/gotty ENTRYPOINT ["gotty"]