38

I am able to start a command line interface (CLI) for a distinct docker container from within Docker Desktop:

enter image description here

If I press an arrow key inside the console window, strange character codes are shown, e.g. if I press the up key, instead of showing the last command, the characters "^[[A" are shown:

enter image description here

=> How can I adapt the shell command?

I tried to set SHELL=/bin/bash in the system environment variables to use bash instead sh but that did not help.

Related:

docker exec bash in windows - keyboard arrow keys don't work

https://github.com/jupyter/notebook/issues/2457

Stefan
  • 10,010
  • 7
  • 61
  • 117
  • 2
    As a workaround, its possible to enter /bin/bash in the sh CLI. Then the arrow keys work as expected. – Stefan Sep 14 '21 at 15:01

2 Answers2

77

I was running CLI from Docker GUI faced the same issue. Solved

  1. From opened CLI run below command
  2. /bin/bash
  3. Then this will see: root@630bc9d304e5:~#
  4. Now you can use Arrow Keys

I hope it will work .

Bushra Mustofa
  • 1,075
  • 7
  • 12
10

For support of arrow keys one needs bash instead of sh. However, bash is not supported by all docker images. I guess that's why docker does not have a configuration option to use bash as a default.

If bash is installed for a specific container, you can symlink sh to bash inside the container, so that bash is used by default. Open a container console and type:

ln -sf /bin/bash /bin/sh

Close the console and open it again. Now you are using bash, supporting arrow key actions.

It's possible to include that in the docker image as well.

Also see:

How to change the default /bin/sh to /bin/bash on opening CLI for selected container in Docker Desktop?

https://phoenixnap.com/kb/symbolic-link-linux

Stefan
  • 10,010
  • 7
  • 61
  • 117
  • that's a really handy trick, tyvm! now I am finally able to use a .bashrc as I used to, under /root/.bashrc – clockw0rk Mar 21 '23 at 13:19
  • This solution doesn't work for me. The behavior remains the same. When I change to the root account, I can up arrow to commands in my history. When I'm not in the root account, I can't. – arnoldbird Apr 19 '23 at 19:42