【发布时间】:2015-05-07 02:30:50
【问题描述】:
我想运行一个ubuntu容器并输入bash:
[root@localhost backup]# docker run ubuntu bash
[root@localhost backup]#
ubuntu 容器直接退出。如何输入bash?
【问题讨论】:
我想运行一个ubuntu容器并输入bash:
[root@localhost backup]# docker run ubuntu bash
[root@localhost backup]#
ubuntu 容器直接退出。如何输入bash?
【问题讨论】:
使用-i 和-t 选项。
示例:
$ docker run -i -t ubuntu /bin/bash
root@9055316d5ae4:/# echo "Hello Ubuntu"
Hello Ubuntu
root@9055316d5ae4:/# exit
$ docker run --help | egrep "(-i,|-t,)"
-i, --interactive=false 即使没有附加 STDIN 也保持打开
-t, --tty=false 分配一个伪TTY
更新:之所以能保持容器运行(运行/bin/bash)是因为-i 和-t 选项(特别是-i) 保持 STDIN 处于打开状态,因此 /bin/bash 不会立即终止,从而终止容器。 -- 你还需要/想要-t 的原因是因为你可能想要一个类似终端的交互式会话,所以t 为你创建了一个新的伪tty。 -- 此外,如果您在不使用-i/-t 选项的情况下查看docker ps -a 的输出,您会看到您的容器以0 的退出代码 正常终止。
【讨论】:
ubuntu容器会退出?加-i -t选项和不加选项能否详细解释一下?
-i, --interactive=false Keep STDIN open even if not attached,attached是什么意思?你能解释一下吗?
-i 本身就是这种情况。
Keep STDIN open even if not attached,那么,如何附加到docker run 中的容器?如果我想使用 STDIN,我似乎必须使用 -i...