docker change Ctrl+p to something else?

后端 未结 5 1643
甜味超标
甜味超标 2021-01-30 16:20

I am using docker run /bin/bash to develop my container and every time I want to use Ctrl+p in a terminal or in emacs, I have to type it twice, since d

相关标签:
5条回答
  • 2021-01-30 16:37

    Here's what worked for me (with a bit more detail than the other answers)

    You modify the docker config file:

    ~/.docker/config.json
    

    For example:

    {
        "auths": {
                "amz": {
                    "auth": key"
                },
                "amz2": {
                    "auth": key2"
                },
                "amz3": {
                    "auth": "key3" }
             },
        "detachKeys": "ctrl-e,e"
    }
    

    NOTE: the detach is no longer ctrl-p,ctrl-q, but rather ctrl-e + e key.

    So the steps are:

    1. Change the config file
    2. Detach from the terminal (using the old/default key bindings)
    3. Attach again (docker exec -it /bin/bash

    Subsequently the new keybindings that you specified should work

    Source: https://github.com/mx4492/dotfiles/commit/bad340b8ddeda6078093e89acacfcba8af74a0cc

    0 讨论(0)
  • 2021-01-30 16:41

    There is now a solution to this so thought I would update it here for others' convenience.

    Just add a ~/.docker/config.json and set your own keybinding.

    {
        "detachKeys": "ctrl-e,e"
    }
    

    Now you can use Ctrl-p in bash and emacs again. Yeah!

    0 讨论(0)
  • 2021-01-30 16:49

    To use this without changing global configuration

    docker exec --detach-keys='ctrl-e,e' -ti foo /bin/bash
    
    0 讨论(0)
  • 2021-01-30 16:53

    Docker has a configuration file and you can change the detach binding by adding

    {
        "detachKeys": "ctrl-z,z"
    }
    

    to ~/.docker/config.json.

    If there are other entries in config.json then just add the "detachKeys" entry as the last one. For example:

    {
        "HttpHeaders": {
            "User-Agent": "Docker-Client/19.03.11 (linux)"
        },
        "detachKeys": "ctrl-z,z"
    }
    

    Note: If you are running docker using sudo docker ... the .docker directory with the configuration file must be in the root's home directory (i.e., /root/.docker/config.json).

    0 讨论(0)
  • 2021-01-30 16:58

    If anyone still can't get Ctrl-P to work inside a container even after changing the detach keys and calling Ctrl-P just prints out ^P in the terminal instead of going up an entry in your history, make sure the shell you're using in the container can actually handle the process signals.

    E.g. instead of docker run -it ... sh.

    Use docker run -it ... bash.

    0 讨论(0)
提交回复
热议问题