实际上,docker run -dit(-itd)与docker run -d之间有什么区别? [英] Practically, what is the difference between docker run -dit(-itd) vs docker run -d?
问题描述
我已经使用 docker run -it
交互地启动容器,并使用 docker run -d
来启动容器背景。这两个选项似乎是排他的。但是,现在我注意到 docker run -dit
(或 docker run -itd
)非常普遍。那么区别是什么呢?当真的需要-它
和 -d
吗?
I've used docker run -it
to launch containers interactively and docker run -d
to start them in background. These two options seemed exclusive. However, now I've noticed that docker run -dit
(or docker run -itd
) is quite common. So what is the difference? When -it
is really needed together with -d
?
推荐答案
是的,有时候,即使您 -d $ c $,也必须包含
-it
c>
Yes, sometimes, it's necessary to include -it
even you -d
-
当
ENTRYPOINT
是bash
或sh
docker run -d ubuntu:14.04
将立即停止,因为 bash
找不到要分配的任何伪终端。您必须指定 -it
,以便 bash
或 sh
可以分配给一个伪终端。
docker run -d ubuntu:14.04
will immediately stop, cause bash
can't find any pseudo terminal to be allocated. You have to specify -it
so that bash
or sh
can be allocated to a pseudo terminal.
docker run -dit ubuntu:14.04
如果要使用 nano
或 vim
和将来的任何容器,您必须在图像开始时指定 -it
。否则会出错。例如,
If you want to use nano
or vim
with any container in the future, you have to specify -it
when the image starts. Otherwise you'll get error. For example,
docker run --name mongodb -d mongo
docker exec -it mongodb bash
apt-get update
apt-get install nano
nano somefile
它将抛出错误
错误打开终端:未知。
这篇关于实际上,docker run -dit(-itd)与docker run -d之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!