Fixing Terminal on Docker exec

The best way to get access to a running Docker container is to use the exec-command docker exec -it <container> /bin/bash. It drops you right into a console within your container. Unfortunately, on some images the terminal is not properly allocated and many commands which are meant to run with a console are not working correctly, e.g. clear results in an error:

root@1e5cd194c97a:/# clear  
TERM environment variable not set.  

The problem is caused by an invalid $TERM environment variable:

root@1e5cd194c97a:/# echo $TERM  
dumb  

And can be fixed easily by running following command:

 export TERM=xterm

Afterwards all console related commands work normally again. The issue is documented in a Github issue in the Docker repository.