-
Notifications
You must be signed in to change notification settings - Fork 18.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange terminal behaviour inside docker #33794
Comments
Ctrl-P/Ctrl-N behave strangely in my case and it's annoying to navigate through the shell history. It's possible that we are troubled by the same issue. |
I have also noticed that navigating through history with up key sometimes reproduces this behaviour. |
I frequently have terminal issues that seem to come down to Docker not figuring out what the right terminal size is initially. This seems to happen only on a fresh terminal. (This may or may not be what's causing your issue.) For example: $ docker exec -it foo /bin/bash
foo@649fb21d747c:~$ stty size
0 0
foo@649fb21d747c:~$ reset -w
foo@649fb21d747c:~$ stty size
24 80
foo@649fb21d747c:~$ # That was still wrong. Now resize the terminal to get a SIGWINCH.
foo@649fb21d747c:~$ stty size
69 208
foo@649fb21d747c:~$ exit
exit
$ docker exec -it foo /bin/bash # Try it again.
foo@649fb21d747c:~$ stty size
69 208
foo@649fb21d747c:~$ # Doesn't happen anymore for this session. |
I have found out that this bug is indeed due to terminal width and height parameters which sometimes is not provided to container with docker exec command You can read more about it in this issue: #10341 I have resolved the bug this way:
You can also put this command in a script and provide container name as parameter and create alias like docker-exec |
Thanks @cromat! This solved an issue I was having using Docker for Windows in Bash on Windows where the output wasn't wide enough due to it not having a proper TTY. It looks like your backticks got formatted into code so here is the line again:
|
for anyone coming here looking for an answer, you can find it here on stackoverflow |
Thanks @PhilT. This is what worked for me.
|
Thanks! That solved mine too! |
After trying a dozen solutions @PhilT 's was the only one that worked |
This is the more correct approach. No need for double-exec of bash. docker exec -e COLUMNS="`tput cols`" -e LINES="`tput lines`" -ti container bash |
@eigood's solution worked like charm at the first try... |
I use ubuntu with gnome. Usually I resize the window and the issue is resolved itself. |
@eigood Thank you for the correct solution. Why won't Docker just do this? |
docker exec doesn't supply terminal width and height values to containers currently. This should really be fixed upstream but this is workaround for the issue until then. There's a 2 year old github issue for it so I doubt it's a priority right now. Before: ``` sme@megatron ~ stty size 48 151 sme@megatron ~ kitchen login root@dokken:/# stty size 0 0 ``` After: ``` sme@megatron ~ stty size 48 151 sme@megatron ~ kitchen login root@dokken:/# stty size 48 151 ``` refs: - moby/moby#33794 - moby/moby#10341 Signed-off-by: Sean Escriva <sean.escriva@gmail.com>
docker exec doesn't supply terminal width and height values to containers currently. This should really be fixed upstream but this is workaround for the issue until then. There's a 2 year old github issue for it so I doubt it's a priority right now. Before: ``` sme@megatron ~ stty size 48 151 sme@megatron ~ kitchen login root@dokken:/# stty size 0 0 ``` After: ``` sme@megatron ~ stty size 48 151 sme@megatron ~ kitchen login root@dokken:/# stty size 48 151 ``` refs: - moby/moby#33794 - moby/moby#10341 Signed-off-by: Sean Escriva <sean.escriva@gmail.com>
…e in fin bash characters may overlap For details see: moby/moby#33794 moby/moby#35407
- added new test checking for custom format dump compatibility - fixed terminal width and height for shell_pg and shell_root commands by setting those using the host terminal width and height see also moby/moby#33794 (comment)
see moby/moby#33794 for details
I created an alias to make my life easier. alias dexec='docker exec -e COLUMNS="`tput cols`" -e LINES="`tput lines`" -ti $1' Eg.: dexec containername_service_1 bash |
@romulo1984 what version of docker are you running? this should be fixed in the current version |
@thaJeztah |
That version reached EOL in March; I'd recommend updating to 18.06 (current stable release), which has the fix for this |
@thaJeztah thanks. |
I can confirm this issue is resolved with Docker 18.06. |
@nodakai I have the same issue as you: I don't have issues with width or anything, but Docker something won't redraw. Specifically, if I use ctrl-p and ctrl-n to scroll through bash history (which is my habit) it doesn't redraw. If I use the arrow keys, it does. Did you manage to find a way around this issue? |
@Grazfather I think that's a different issue. I think the issue there is that the key sequence to detach from a container is |
The answer linked to here is the best solution imo because other solutions don't work when you switch users inside the container, assuming you want the new user's environment which will overwrite the LINES and COLUMNS environment variables. |
Docker-compose example to solve this problem:
Focus on environment. @cromat thanks! |
@frops your solution is invalid. the besides, as I read @thaJeztah said it's fixed in 18.06 |
Should definitely be improved in 18.06 and up, but there are still some cases where the resize may need to be retriggered (you can do so by resizing your terminal window); there's a pull request that adds a retry-loop for those cases, but it's not merged yet; docker/cli#1529 I'd consider setting |
I found the bug is still present if running with Example to reproduce:
Command with broken output / wrong terminal size: |
docker/cli#1529 is not yet in `Docker 18.09 |
expected to be fixed in 19.03.0 (10th July 2019) |
It was back ported to Docker CLI 18.09.5 through docker/cli#1775 |
still presents in the latest Mac OS when compile openwrt with command:
|
I made myself a portable VIM configuration with all my fancy plugins for style and linting/fixing. Until I came up with @cromat solution I always had layout issues with VIM + NERDTree. Now it works well. Just made myself an alias (function, I like functions but same thing here). $ vi ~/.zshrc function vim {
docker run --env LINES=$(tput lines) --env COLUMNS=$(tput cols) # ...
} |
If the detection of the windows size fails in a BASH script and you're getting the default docker exec -e COLUMNS="$(stty size | awk '{print $2}')" -e LINES="$(stty size | awk '{print $1}')" \
-it container //bin/bash Regards, |
When I exec to /bin/bash inside docker (docker exec -ti container /bin/bash) and search recursive for a command, sometimes terminal starts to behave strange and everything messes up like in picture.
![selection_017](https://user-images.githubusercontent.com/3780307/27479588-cb3eb540-5814-11e7-8b19-301644edc2fc.png)
After that I have to exit from container and exec in again.
The text was updated successfully, but these errors were encountered: