更新时间:2023-11-22 17:36:10
只要您指定的命令与Docker容器一样运行 CMD
, ENTRTYPOINT
或通过命令行运行。在您的情况下,服务
命令立即完成,整个容器关闭。
Docker container runs as long as the command you specify with CMD
, ENTRTYPOINT
or through the command line is running. In your case the service
command finishes right away and the whole container is shut down.
解决此问题的一种方法是直接从命令行启动nginx(确保你不作为守护进程运行它)。
One way to fix this is to start nginx directly from the command line (make sure you don't run it as a daemon).
另一个选项是创建一个启动服务的小脚本然后永远睡觉。如下:
Another option is to create a small script which starts the service and then sleeps forever. Something like:
#!/bin/bash
service nginx start
while true; do sleep 1d; done
并运行它,而不是直接运行服务
命令。
and run this instead of directly running the service
command.
第三个选项是使用像 runit 或类似的程序,而不是正常的服务。
A third option would be to use something like runit or similar program, instead of the normal service.