原有nginx镜像中CMD是,如下图

如果想自定义启动脚本, 最终在启动nginx
以下是自定义脚本内容:特别注意nginx的启动和原有启动保持一致

官方解释
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)!
如果你在Dockerfile中添加了一个自定义CMD,一定要关闭-g守护进程;
为了让nginx留在前台,
这样Docker就可以正确地跟踪进程(否则你的容器会在启动后立即停止)!

本文详细介绍了在Dockerfile中自定义CMD指令时,如何确保nginx服务在容器中正常运行而不立即退出的方法。强调了在自定义CMD中加入-g daemon off参数的重要性,以使nginx留在前台运行,便于Docker跟踪进程。
5453

被折叠的 条评论
为什么被折叠?



