gpt4 book ai didi

docker run -it 通过 ssh : the input device is not a TTY

转载 作者:行者123 更新时间:2023-12-02 03:43:00 25 4
gpt4 key购买 nike

我想直接通过 ssh 命令以交互方式运行 docker 容器。

我当前的代码如下所示(我使用 echo hi 作为占位符):

$ ssh vagrant@127.0.0.1 -p 2222 "docker run -ti ubuntu:xenial echo hi"
the input device is not a TTY

我还尝试显式制作交互式登录 shell:

$ ssh vagrant@127.0.0.1 -p 2222 "bash -ilc 'docker run -ti ubuntu:xenial'"
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
the input device is not a TTY

如果我通过 ssh 并交互运行该命令,效果会很好:

$ ssh vagrant@127.0.0.1 -p 2222
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-34-generic x86_64)

* Documentation: https://help.ubuntu.com/
----------------------------------------------------------------
Ubuntu 14.04.5 LTS built 2016-08-26
----------------------------------------------------------------
Last login: Mon Oct 30 23:25:35 2017 from 10.0.2.2
vagrant@vagrant:~$ docker run -ti ubuntu:xenial echo hi
hi

我在这里缺少什么?

最佳答案

当在参数列表上传递显式命令时(与运行远程交互式 shell 作为默认操作相反),默认情况下 SSH 不会设置 TTY。要解决此问题,请添加 -tt:

$ ssh -tt vagrant@127.0.0.1 -p 2222 "docker run -ti ubuntu:xenial echo hi"

当且仅当存在本地 TTY 时,单个 -t 才会设置远程 TTY; -tt 无条件地这样做。

RequestTTY 选项也可以在命令行上显式设置:

$ ssh -o 'RequestTTY force' vagrant@127.0.0.1 -p 2222 \
> 'docker run -ti ubuntu:xenial echo hi'

...或在~/.ssh/config中:

Host vagrant
HostName 127.0.0.1
Port 2222
User vagrant
RequestTTY force

...用作:

ssh vagrant 'docker run -ti ubuntu:xenial echo hi'
<小时/>

引用the man page for ssh :

-t - Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.

引用the ssh_config man page :

RequestTTY - Specifies whether to request a pseudo-tty for the session. The argument may be one of: no (never request a TTY), yes (always request a TTY when standard input is a TTY), force (always request a TTY) or auto (request a TTY when opening a login session). This option mirrors the -t and -T flags for ssh(1).

关于docker run -it 通过 ssh : the input device is not a TTY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47025758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com