Skip to content

Commit

Permalink
Merge pull request #536 from CybCom/master
Browse files Browse the repository at this point in the history
Fix expression of using init
  • Loading branch information
yeasy authored Dec 20, 2023
2 parents 3ccba8a + 46020ff commit dd6b022
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion image/dockerfile/cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CMD service nginx start

对于容器而言其启动程序就是容器应用进程容器就是为了主进程而存在的主进程退出容器就失去了存在的意义从而退出其它辅助进程不是它需要关心的东西

而使用 `service nginx start` 命令则是希望 upstart 来以后台守护进程形式启动 `nginx` 服务而刚才说了 `CMD service nginx start` 会被理解为 `CMD [ "sh", "-c", "service nginx start"]`因此主进程实际上是 `sh`那么当 `service nginx start` 命令结束后`sh` 也就结束了`sh` 作为主进程退出了自然就会令容器退出
而使用 `service nginx start` 命令则是希望 init 系统以后台守护进程的形式启动 nginx 服务而刚才说了 `CMD service nginx start` 会被理解为 `CMD [ "sh", "-c", "service nginx start"]`因此主进程实际上是 `sh`那么当 `service nginx start` 命令结束后`sh` 也就结束了`sh` 作为主进程退出了自然就会令容器退出

正确的做法是直接执行 `nginx` 可执行文件并且要求以前台形式运行比如

Expand Down

0 comments on commit dd6b022

Please sign in to comment.