起因
起初使用旧版本时没有发现这个问题,但是升级到Docker 17.12.0-ce-mac49
后间歇性发生
经过
忍耐
起初不以为意,然后发现打开vim后行列明显少了很多。
于是,clear
,退出docker,clear
,再进入docker,有时好有时不好
尝试解决
发现改变窗口大小后没有问题了,估计是docker适配的问题
结果
解决方案
在docker exec -it
后添加-e LINES=$(tput lines) -e COLUMNS=$(tput cols)
结合我的debian就是
docker exec -it -e LINES=$(tput lines) -e COLUMNS=$(tput cols) debian bash -C
原因
docker run -dit --name test-lines debian \
bash -c 'while true; do date; tput lines; sleep 1; done' \
&& sleep 5 && docker logs test-lines && docker attach test-lines
通过5秒后docker attach发现tty resize是在容器启动后再修改的。
因此在官方修复前,只能暂时打开时指定好行数和列数。
参考资料
docker issue: Line wrapping issue typing long commands in bash
moby issue: Docker number of lines in terminal changing inside docker
moby issue: Docker Exec does not resize terminal