Docker下Ctrl-p和Ctrl-n的行为异常 [英] Ctrl-p and Ctrl-n behaving unexpectedly under Docker
问题描述
在我的一生中,我似乎无法弄清为什么 ctrl - p 和 ctrl - n 不能像我应该使用的Docker镜像下那样工作. ctrl - p 应该像 up 箭头一样工作,但是我通常必须按两次以获取我运行的最后一个命令.它以一种似乎是随机的方式循环浏览历史.
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-p should work just like the up arrow but I usually have to press it twice to get the last command I ran. 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
如果在此处按 up ,它将显示touch
命令,后跟ls
.
但是,如果按 Ctrl - p ,则第一时间没有任何结果.当我再次按下它时,ls
会神奇地出现.
If I press up here, it should show the touch
command, followed by ls
.
If I press Ctrl-p however, nothing comes up the fist time. When I press it again, ls
appears magically.
有人可以帮我弄清楚这些吗?我不能没有 Ctrl - p 和 Ctrl - n .
Can someone help me make sense of these. I can't live without Ctrl-p and Ctrl-n.
推荐答案
在Google文档中,它似乎已被删除(或移动),但是它曾经存在于这里:
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/
编辑:它们似乎在配置文件文档.
要从Docker容器中分离的命令序列为 ctrl - p ctrl - q 为什么 ctrl - p 无法按预期工作.当您按下 ctrl - p 时,泊坞窗正在等待 ctrl - q ,因此什么也没发生.
The command sequence to detach from a docker container is ctrl-p ctrl-q, which is why ctrl-p doesn't work as expected. When you hit ctrl-p, docker is waiting on ctrl-q, so nothing happens.
您可以使用docker run
的新--detach-keys
参数来覆盖此序列,使其成为 ctrl - p 之外的其他内容:
You can use the new --detach-keys
argument to docker run
to override this sequence to be something other than 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
如果需要,可以将其添加到您的~/.docker/config.json
文件中以保留此更改:
If you want, you can add this to your ~/.docker/config.json
file to persist this change:
{
...
"detachKeys": "ctrl-@",
...
}
可在此处找到更多详细信息: https://github.com/docker/docker /pull/15666 ,因为我在文档中找不到它.
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.
这篇关于Docker下Ctrl-p和Ctrl-n的行为异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!