Docker: Running nano in docker container

Docker

Docker 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMyles McDonnellView Question on Stackoverflow
Solution 1 - DockerJavier CortejosoView Answer on Stackoverflow
Solution 2 - DockerNaresh WaliaView Answer on Stackoverflow
Solution 3 - DockerseanmclView Answer on Stackoverflow
Solution 4 - DockeralfonsoolavarriaView Answer on Stackoverflow
Solution 5 - DockerpHiLView Answer on Stackoverflow
Solution 6 - DockerRawand SaeedView Answer on Stackoverflow
Solution 7 - DockerworkdreamerView Answer on Stackoverflow
Solution 8 - DockermuffirView Answer on Stackoverflow
Solution 9 - DockerHayroView Answer on Stackoverflow