docker change Ctrl+p to something else?

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


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!


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

Tags:

Docker