简体   繁体   English

Ctrl-p和Ctrl-n在Docker下意外运行

[英]Ctrl-p and Ctrl-n behaving unexpectedly under Docker

For the life of me I can't seem to figure out why ctrl - p and ctrl - n don't work like they're supposed to under the Docker images I have been working with. 对于我的生活,我似乎无法弄清楚为什么ctrl -pctrl -n不能像我们一直在使用的Docker图像那样工作。 ctrl - p should work just like the up arrow but I usually have to press it twice to get the last command I ran. ctrl -p应该像向上箭头一样工作但我通常必须按两次才能得到我运行的最后一个命令。 And it cycles through the history in what seems to be a random fashion. 它以似乎是随机的方式在历史中循环。

Maybe someone can help me make some sense of this. 也许有人可以帮助我理解这一点。

docker run -it buildpack-deps:trusty # run a Linux based image

root@74cbcf321fae:/# ls
bin  boot  dev  etc  home  lib  lib64  ...
root@74cbcf321fae:/# touch hello

If I press up here, it should show the touch command, followed by ls . 如果我这里按下,它应该显示touch命令,然后是ls If I press Ctrl - p however, nothing comes up the fist time. 如果我按下Ctrl - p然而,第一次没有任何事情发生。 When I press it again, ls appears magically. 当我再次按下它, ls出现神奇。

Can someone help me make sense of these. 有人可以帮我理解这些。 I can't live without Ctrl - p and Ctrl - n . 没有Ctrl - pCtrl - n我就活不下去。

It looks like this has been removed (or moved) in the Docs, but it used to live here: https://docs.docker.com/engine/reference/commandline/attach/ 看起来这已经在文档中删除(或移动),但它曾经住在这里: https//docs.docker.com/engine/reference/commandline/attach/

Edit : It looks like they reference the below in the Configuration Files documentation. 编辑 :看起来他们在配置文件文档中引用了下面的内容。

The command sequence to detach from a docker container is ctrl - p ctrl - q , which is why ctrl - p doesn't work as expected. 从docker容器中分离的命令序列是ctrl -p ctrl -q ,这就是ctrl -p无法按预期工作的原因。 When you hit ctrl - p , docker is waiting on ctrl - q , so nothing happens. 当你点击ctrl - p时 ,docker正在等待ctrl -q ,所以没有任何反应。

You can use the new --detach-keys argument to docker run to override this sequence to be something other than ctrl - p : 您可以使用新的--detach-keys参数进行docker run以覆盖此序列,使其不是ctrl -p

docker run -ti --detach-keys="ctrl-@" ubuntu:14.04 bash

$# ls
$# <--- Ctrl-P here will display ls now
$# <--- Ctrl-@ here will detach from the running container

If you want, you can add this to your ~/.docker/config.json file to persist this change: 如果需要,可以将其添加到~/.docker/config.json文件中以保留此更改:

{
    ...
    "detachKeys": "ctrl-@",
    ...
}

More details on this can be found here: https://github.com/docker/docker/pull/15666 as I can't find it in the docs anymore. 有关这方面的更多详细信息,请访问: https//github.com/docker/docker/pull/15666,因为我在文档中找不到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM