What's the reason Docker Ubuntu official image would exit immediately when you run/start it?

喜夏-厌秋 提交于 2021-01-20 13:14:12

问题


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.

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?


回答1:


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

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



来源:https://stackoverflow.com/questions/37599263/whats-the-reason-docker-ubuntu-official-image-would-exit-immediately-when-you-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!