我想在Docker容器中自动启动服务NGINX,
我尝试在DOCKERFILE FILE中添加此代码,但该服务并未自动启动。
RUN service nginx start
CMD service nginx start
答案 0 :(得分:0)
问题是这个服务/守护进程将在后台运行。
阅读以下文章了解更多信息 的 How to Run a Daemon Service in the Foreground 强>
快速解决方法是将CMD或ENTRYPOINT替换为 您必须找出启动命令才能在前台运行。
(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"]
或相应地调整它。
如果您需要更多帮助,请在评论部分告诉我。