在容器环境,one container == one process,容器要能持续运行,必须有且仅有一个前台进程,所以对nginx进程容器化,需要将nginx转为前后进程( daemon off)。
“
我们能顺利执行docker run nginx,启动容器并不退出,是因为nginx的官方镜像Dockerfile[1] 已经指定 nginx -g "daemon off;"
再回到上文,为什么此处脚本中要加"nginx -g "daemon off;" 呢?
“
If you add a custom CMD in the Dockerfile, be sure to include -g daemon off; in the CMD in order for nginx to stay in the foreground, so that Docker can track the process properly (otherwise your container will stop immediately after starting)!