Docker自动启动服务NGINX

Docker自动启动服务NGINX,docker,nginx,service,dockerfile,Docker,Nginx,Service,Dockerfile,我想在Docker容器中自动启动服务NGINX 我尝试在DOCKERFILE文件中添加此代码,但服务无法自动启动 RUN service nginx start CMD service nginx start 问题是此服务/守护程序将在后台运行。 阅读下面的文章以了解更多信息 快速解决方法是将CMD或ENTRYPOINT替换为 要在前台运行,您必须了解start命令 (Note: Daemon Service = Binary + Configuration + Initscript.)

我想在Docker容器中自动启动服务NGINX

我尝试在DOCKERFILE文件中添加此代码,但服务无法自动启动

RUN service nginx start
CMD service nginx start

问题是此服务/守护程序将在后台运行。

阅读下面的文章以了解更多信息

快速解决方法是将CMD或ENTRYPOINT替换为 要在前台运行,您必须了解start命令

(Note: Daemon Service = Binary + Configuration + Initscript.)

To run the process in the foreground, we just need these two ingredients:

Binary: bash -x /etc/init.d/XXX start.
Here, -x instructs shell to display verbose output. Should be easy to figure out binary path. Another trick is _”ps -ef | grep $PROCESS_PATTERN”_.
Configuration: Typically speaking, we can dig out from console output of bash -x. Sometimes, it’s just too long to read. Figure out the process ID and the list environment from cat /proc/$pid/environ.
A lot of decent services refuse to run as root because of security concerns. Here is how to impersonate other users with root.
所以在您的情况下,可执行命令应该是

CMD ["bash", "-x", "/etc/init.d/nginx","start"]
或者相应地对其进行检查。
如果您需要更多帮助,请在评论部分告诉我