bash 如何让 docker debian 容器保持打开状态?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34863645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:07:14  来源:igfitidea点击:

How can I keep a docker debian container open?

bashubuntudockerdebiandockerfile

提问by sgarcia.dev

I want to use a debian Docker container to test something, and by this I mean execute some commands in the debian bash console. I tried downloading the image using docker pull debianand then running it using docker run debian, but I get no output. What am I doing wrong? Shouldn't the docker container stay open until I close it?

我想使用 debian Docker 容器来测试一些东西,我的意思是在 debian bash 控制台中执行一些命令。我尝试使用 下载图像docker pull debian,然后使用运行它docker run debian,但没有输出。我究竟做错了什么?docker 容器在我关闭之前不应该保持打开状态吗?

回答by Bryan Oakley

You need to explicitly run bash:

您需要显式运行 bash:

docker run -it debian /bin/bash

The -imeans "run interactively", and -tmeans "allocate a pseudo-tty".

-i“交互运行”的意思,而-t意味着“分配伪终端”。

A good place to read a bit more is the section Running an interactive shellin the Quickstart documentation.

阅读更多内容的好地方是快速入门文档中的运行交互式 shell部分。