我正在用 docker 做一些复杂的事情,但结果我不知道 -it
标志是什么意思。
最近我遇到了一些 docker run
命令的例子,这让我有点困惑。
docker run -itd ubuntu:xenial /bin/bash
我的问题是,如果容器在实例化期间运行 bin/bash
-it
标志有什么意义
在文档中我们有一个例子
docker run --name test -it debian
有解释
The -it instructs Docker to allocate a pseudo-TTY connected to the container’s stdin; creating an interactive bash shell in the container.
帮助页面中-t
标志的解释
-t, --tty Allocate a pseudo-TTY
如果我在
期间删除-it
标志
docker run -d ubuntu:xenial /bin/bash
我新创建的容器不活了
在 docker ps -a
它被指定为退出
对不起,如果我的问题很愚蠢,我在互联网上找不到解释(我对这一点有很大的误解)。
最佳答案
-it
是 --interactive
+ --tty
的缩写。当您使用此命令 docker run
时,它会将您直接带入容器。
-d
是 --detach
的缩写,这意味着您只需运行容器,然后从中 detach。本质上,您在后台运行容器。
编辑: 因此,如果您使用 -itd
运行 Docker 容器,它会同时运行 -it
选项并将您与容器分离.因此,即使没有运行任何默认应用,您的容器仍将在后台运行。
关于docker - 什么是 docker run -it 标志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48368411/