linux中-i选项的作用,linux – “docker exec”命令的“-i”和“-t”选项的用途是什么?...

本文探讨了Docker运行容器时如何使用-i和-t标志。-i标志保持stdin打开,允许交互式输入,而-t标志分配一个伪TTY,用于交互式会话。在17.06之前的Docker版本中,使用docker exec可能存在tty问题,但在17.06之后已修复。文章还提到了docker run和docker exec在分配TTY时的差异及其在不同操作系统上的行为。
摘要由CSDN通过智能技术生成

-i, – interactive使STDIN保持打开即使没有附加,如果你想输入任何命令,你需要它.

-t,–tty分配一个伪TTY,一个连接用户的“终端”与stdin和stdout的pseudo terminal. (见container/container.go)

如果你做回声,只需要-t.

但是对于输入输入的交互式会话,您需要-i.

由于-i保持stdin打开,因此它也用于将输入管道输送到分离的docker容器.即使使用-d(分离)也可以.

见“When would I use --interactive without --tty in a Docker container?”:

$echo hello | docker run -i busybox cat

hello

-i keeps STDIN open even if not attached, what is the status of STDOUT in this case?

对于docker exec来说,它是由docker run设置的.

但是,关于docker exec,目前存在一个问题(issue 8755: Docker tty is not a tty with docker exec

unfortunately your discovery only amounts to a difference between the behaviour of tty in centos6 vs ubuntu:14.04. There is still not a functional tty inside the exec – just do ls -la /proc/self/fd/0 and see that it’s a broken link pointing to a pts which doesn’t exist.

the actual bug we’re dealing with is that certain standard libraries assume that the symlinks in /proc/self/fds/ must be valid symlinks

The problem is that the tty is created outside on the host and there is no reference to it in the container like how /dev/console is setup in the primary container.

One options to fix this would be allocate and bind mount the devpts from the host in to the containers.

注(2017年第4季度):this should been fixed by now (docker 17.06-ce).

见PR 33007.

PR现在允许(从17.06开始):

zacharys-pro:dev razic$docker run --rm -t -d ubuntu bash

83c292c8e2d13d1b1a8b34680f3fb95c2b2b3fef71d4ce2b6e12c954ae50965a

zacharys-pro:dev razic$docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

83c292c8e2d1 ubuntu "bash" 2 seconds ago Up 1 second xenodochial_bardeen

zacharys-pro:dev razic$docker exec -ti xenodochial_bardeen tty

/dev/pts/1

(在17.06之前,tty回来了“不是tty”)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值