Thursday, December 21, 2017

Docker Bash shell and Ctrl+P

If you are running an interactive Bash shell in a Docker container running Linux, the Ctrl+P key does not perform the previous-history command, which fetches the previous entry in the command history entry and repeats it at the current prompt. But if you press Ctrl+P twice, it happens to work.

The reason for this is that Docker's interactive mode assigns "Ctrl+P Ctrl+Q" to detach from the interactive Docker session. To fix this, I customize the detach keys using --detach-keys command line option:

$ docker run -it --detach-keys 'ctrl-z,ctrl-q' ubuntu bash

Ctrl+P now works as expected!