Docker: Running nano in docker container
DockerDocker Problem Overview
I open an interactive shell into a docker container like so
sudo docker exec -t -i {container_name} bash
So far so good but trying to run nano
results in:
>Error opening terminal: unknown.
Docker Solutions
Solution 1 - Docker
I think this can be related with Docker Issue #9299.
There are some workarounds commented in that issue:
- Run the container allocating a pseudo-TTY (option
-t
). - Export environment variable $TERM=xterm in the container's process run in exec (i.e.:
export TERM=xterm
)
Solution 2 - Docker
Run comand : export TERM=xterm
Solution 3 - Docker
You can add
ENV TERM xterm
to your Dockerfile if you will use the editor regularly. We have that setting in our base container, since we're constantly debugging things with vi/emacs.
Solution 4 - Docker
docker exec -it id_container bash
apt-get update
apt-get install nano
export TERM=xterm
Solution 5 - Docker
as $TERM
was already set to xterm
but still not working for me, here is a way that worked: docker exec -it [CONTAINER_ID] /bin/bash -c "export TERM=xterm; exec bash"
Solution 6 - Docker
Run this command in your container apk add nano
Solution 7 - Docker
I did a workaround, in my .bashrc i have added:
alias nano='export TERM=xterm && nano'
In this case the error no longer appear
Solution 8 - Docker
For me export TERM=xterm
causes some display issues described here:
https://superuser.com/questions/1172222/issues-editing-files-with-nano-in-bash-windows-10
In that case export TERM=linux
may works better.
Solution 9 - Docker
I don't know if we are talking about the same thing but you need to make apt update | apt install nano
so you can install it in the container.