运行/启动Docker Ubuntu官方映像会立即退出的原因是什么? [英] What's the reason Docker Ubuntu official image would exit immediately when you run/start it?

查看:129
本文介绍了运行/启动Docker Ubuntu官方映像会立即退出的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道当主进程退出时,容器将退出.我的问题是关于它背后的原因,而不是如何使其工作.我当然知道我可以传递参数 -it 以交互方式开始.

I understand that a container will exit when the main process exit. My question is about the reason behind it, not how to get it to work. I of course know that I could pass the parameter -it to start with interactive mode.

根据映像Dockerfile启动时,Ubuntu映像将运行/bin/bash .bash进程不应该等待用户输入命令而不退出吗?(就像在主机上运行/bin/bash 时一样,它将启动一个交互式shell,等待用户输入而不退出).为什么Docker Ubuntu的bash立即退出?

The Ubuntu image will run /bin/bash when it starts according to the image Dockerfile. Shouldn't bash process wait for user input commands and not exit? (just like when you run /bin/bash in the host machine, it would start an interactive shell and wait for user inputs and not exit) Why would the Docker Ubuntu's bash exit right away?

推荐答案

没有 -it 的容器没有TTY,也没有附加 stdin ,因此bash开始并完成紧随其后.

Without -it the container has no TTY, and no stdin attached, so bash starts and completes directly after.

您可以通过添加 -d 选项(使 docker run -dit ubuntu )以分离模式启动容器来保持容器运行

You can keep the container running by adding the -d option (so docker run -dit ubuntu) to start it in detached mode

这篇关于运行/启动Docker Ubuntu官方映像会立即退出的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆