gpt4 book ai didi

docker - 为什么 CTRL-C 不再停止我的 nginx 容器?

转载 作者:行者123 更新时间:2023-12-01 04:50:06 27 4
gpt4 key购买 nike

我正在试验基于 nginx 的 Dockerfile。最后一行目前看起来像这样:

FROM nginx:alpine
... # not really relevant
CMD /bin/sh -c "envsubst < /etc/nginx/conf.d/site.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"

现在,当我使用 docker run my-nginx-image 运行容器时,我注意到 CTRL-C不再停止容器。

在此更改之前,我有以下 CMD最后声明:

CMD ["nginx", "-g", "daemon off;"]

在这里,CTRL-C按预期工作:容器已停止。这是为什么?我怎样才能拥有两个世界?

  • CTRL-C工作
  • envsubst包括

更新

经过一番阅读,我意识到我必须使用 CMD [...] 进行引导.但是我没能整合整个命令 envsubst < ... > ... && nginx -g 'daemon off;'进入[...]语法。

最佳答案

https://forums.docker.com/t/docker-run-cannot-be-killed-with-ctrl-c/13108/2

So there are two factors at play here:

If you specify a string for an entrypoint, like this:

ENTRYPOINT /go/bin/myapp

Docker runs the script with /bin/sh -c 'command'. This intermediate script gets the SIGTERM, but doesn’t send it to the running server app.

To avoid the intermediate layer, specify your entrypoint as an array of strings.

ENTRYPOINT ["/go/bin/myapp"]

关于docker - 为什么 CTRL-C 不再停止我的 nginx 容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48646455/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com