moby: Docker Exec does not resize terminal
I noticed this on both master
(and docker 17.11-rc2, both on Ubuntu and Docker for Mac);
Client:
Version: 17.11.0-ce-rc2
API version: 1.34
Go version: go1.8.3
Git commit: d7062e5
Built: Wed Nov 1 22:11:59 2017
OS/Arch: linux/amd64
Server:
Version: 17.11.0-ce-rc2
API version: 1.34 (minimum version 1.12)
Go version: go1.8.3
Git commit: d7062e5
Built: Wed Nov 1 22:10:29 2017
OS/Arch: linux/amd64
Experimental: false
When running docker exec
, the terminal doesn’t resize:
$ docker run -d --name foo nginx:alpine
$ docker exec -it foo sh
/ # 0123456789012345678901234567890123456789012345678901234567890123456789012345
6789
Checking the size with stty size
does show the correct dimensions:
/ # stty size
93 410
This only happens on docker exec
; doing docker run -it
works correct:
$ docker run -it --rm nginx:alpine sh
/ # 01234567890123456789012345678901234567890123456789012345678901234567890123456789
(and shows the same output for stty size
):
/ # stty size
93 410
Checking the daemon logs, the resize parameters are passed to the API for both docker run
and docker exec
;
time="2017-11-04T00:17:19.801321056Z" level=debug msg="Calling POST /v1.34/containers/378120448a6af3b289c12574445dde6f7a5a8f6fb09a311a46d1ffc735fab010/resize?h=93&w=410"
time="2017-11-04T00:16:37.697677138Z" level=debug msg="Calling POST /v1.34/exec/c57124724228e4af259281af94206ce9f02c64e472408198f665b342c1347f03/resize?h=93&w=410"
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 24
- Comments: 31 (14 by maintainers)
Commits related to this issue
- Add workaround for https://github.com/moby/moby/issues/35407 — committed to jschwartzentruber/docker-bootstrap by jschwartzentruber 6 years ago
- Correct Docker container terminal sizing Containers accessed via `molecule login` are not getting $COLUMNS and $LINES set. Update docker exec to pass the proper $COLUMNS and $LINES env vars [1] as a... — committed to retr0h/molecule by retr0h 6 years ago
- Correct Docker container terminal sizing (#1246) Containers accessed via `molecule login` are not getting $COLUMNS and $LINES set. Update docker exec to pass the proper $COLUMNS and $LINES env var... — committed to ansible/molecule by retr0h 6 years ago
- Fix redraw issue Based: https://github.com/moby/moby/issues/35407\#issuecomment-357093710 — committed to iaguara/iaguara by fiuzagr 6 years ago
- fin 1.56.1. Fix (workaround) the docker bug that when typing long line in fin bash characters may overlap For details see: https://github.com/moby/moby/issues/33794 https://github.com/moby/moby/issue... — committed to docksal/docksal by achekulaev 6 years ago
- dce (docker-exec) alias: pass COLUMNS and LINES env vars from current terminal Taken from [this discussion][1]. Otherwise, using binding.pry with this 'dce' alias is nearly impossible. [1]: https:/... — committed to tadas-s/dotfiles by tadas-s 6 years ago
- Remove COLUMNS/LINES workaround Originally introduced by 6e53837d3 and other commits; this workaround is no longer necessary since the bug in Docker was squashed: https://github.com/moby/moby/issues... — committed to gmta/docksal by deleted user 6 years ago
- Pass size of the external tty into the container Workaround the issue in Docker where the terminal has a strange size: https://github.com/moby/moby/issues/35407 This issue is purportedly fixed but I... — committed to mergermarket/cdflow by grahamlyons 5 years ago
- Pass size of the external tty into the container Workaround the issue in Docker where the terminal has a strange size: https://github.com/moby/moby/issues/35407 This issue is purportedly fixed but I... — committed to mergermarket/cdflow by grahamlyons 5 years ago
So, this still seems to be an issue. My workaround for now is setting the
COLUMNS
andLINES
environment variables in the Exec.The suggestion of resizing the window is an interesting one. It makes it seem that the SIGWINCH signal propagates the terminal size correctly. A small test …
Start a TTY via
docker exec
:On the host, send a SIGWINCH to the
docker exec
process:Re-run
stty
in the same TTY as the first step:It seems that an initial SIGWINCH on the start of the TTY is missed or isn’t sent (correctly).
Fixed on master through https://github.com/moby/moby/pull/37172
This indeed seems an issues since the early 17.11 releases. It’s quite easy to reproduce:
17.11.0-ce
)docker run -ti --name shelltest ubuntu bash
top
and verify it’s in full screen/terminaldocker exec -ti shelltest bash
top
and see it starts in a 80x24 boundaryNo issue in =< 17.10.
Yes, sorry this is still in my list. Unfortunately, I still haven’t gotten around setting up a proper working env for docker-ce (the mono-repo doesn’t make it easy 😅). I’ll try to dedicate some time to it in the next couple weeks.
The SIGWINCH workaround, suggested by @mpepping is much better than setting COLUMNS and LINES envs because it also supports resizing of the terminal window, without the need to restart Docker exec every time your terminal size changes. However the issue was that it had to be manually run every time after docker exec, so here’s my workaround:
If you use Makefile, you can add:
and create
fix-docker-terminal.bash
in the same directory:Do not forget to
chmod +x fix-docker-terminal.bash
.If you don’t use Makefile, you can go with this one line:
./fix-docker-terminal.bash & docker exec -it -u www-data container zsh
@thaJeztah Thanks! This will probably make a lot of people happy! 👍
Any updates here? @mlaventure Three months since your comment, did you find time to fix this?
Yes, it looks like a race condition, and likely the initial resize is triggered to early; cli/command/container/tty.go#L48. Moving the resize to the end of that function (or adding another resize after monitoring is started; cli/command/container/exec.go#L156-L160) seems to help slightly, but it’s still racy.
So, this may actually be the same issue as https://github.com/moby/moby/issues/31223
ping @mlaventure
I am getting this issue again on a fresh docker installation:
pi@rpi-dev:~ $ docker run -ti hello-world failed to resize tty, using default size
pi@rpi-dev:~ $ docker --version Docker version 19.03.12, build 48a6621
This is a fresh docker installation on a raspberry pi (raspbian). Any help would be greatly appreciated. TIA.