如果将应用程序引导到entrypoint.sh中,该应用程序是否将以PID 1运行并收到信号? [英] Will the application run as PID 1 and will signals be received if we bootstrap it in a entrypoint.sh?
问题描述
使用来启动服务是一个很好的习惯
CMD ["/go/bin/myapp"]
代替
CMD /go/bin/myapp
以第一种方式,SIGTERM被应用程序捕获,而在第二种方式中,底层的/bin/sh
脚本捕获了SIGTERM,该脚本不将它们转发给服务.我从 https:中学到了这一点: //forums.docker.com/t/docker-run-can-be-killed-with-ctrl-c/13108/2 .
现在我想知道CMD ["..."]
是否完全等同于将...
放入/entrypoint.sh
脚本并调用CMD ["/entrypoint.sh"]
?现在,子应用程序也将以PID 1的身份运行并因此接收所有信号吗?
作为一个具体的例子,我想创建一个脚本:
envsubst < /etc/nginx/conf.d/site.template > /etc/nginx/conf.d/default.conf
&&
nginx -g 'daemon off;'
然后在我的Dockerfile
末尾致电CMD ["/entrypoint.sh"]
.这样安全吗,尽管脚本中有多个命令(envsubst
和ngingx
),nginx仍将以PID 1的形式运行吗?
这件事使我感到困惑,我试图弄清楚何时以及何时不使用tini
( https: //github.com/krallin/tini ).
在这里,我尝试遵循MySQL 5.7 docker-entrypoint.sh: 想法是在 相关示例与 It's good practice to start the service with instead of In the first way, SIGTERMs are caught by the applicaiton, while in the second way, they are caught by the underlying Now I am wondering if As a concrete example, I want to create a script with: And call This matter confuses me and I am trying to figure out when and when not to use Here is my try to follow what also the MySQL 5.7 Dockerfile: docker-entrypoint.sh: The idea is to do anything needed as a preparation inside the Link of relevant example to 这篇关于如果将应用程序引导到entrypoint.sh中,该应用程序是否将以PID 1运行并收到信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!#!/bin/bash
set -e
echo "preparing..."
exec "$@"
docker-entrypoint.sh
脚本中做任何准备工作,然后使用exec "$@"
将信号传递到CMD
. (这意味着您必须在docker-entrypoint.sh
内部使用envsubst < /etc/nginx/conf.d/site.template > /etc/nginx/conf.d/default.conf
)
Dockerfile
文档的链接: 如果您需要为单个可执行文件编写启动脚本,则可以使用exec
和gosu
命令来确保最终的可执行文件接收Unix信号... >CMD ["/go/bin/myapp"]
CMD /go/bin/myapp
/bin/sh
script, which does not forward them to the service. I learned this from https://forums.docker.com/t/docker-run-cannot-be-killed-with-ctrl-c/13108/2.CMD ["..."]
is completely equivalent to putting ...
in an /entrypoint.sh
script and calling CMD ["/entrypoint.sh"]
? Will now child applications also be running as PID 1 and therefore receive all signals?envsubst < /etc/nginx/conf.d/site.template > /etc/nginx/conf.d/default.conf
&&
nginx -g 'daemon off;'
CMD ["/entrypoint.sh"]
at the end of my Dockerfile
. Is this safe and will nginx run as PID 1 despite that there are multiple commands (envsubst
and ngingx
) in the script?tini
(https://github.com/krallin/tini).Dockerfile
does... but with an Nginx image. FROM nginx:latest
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod 777 /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
#!/bin/bash
set -e
echo "preparing..."
exec "$@"
docker-entrypoint.sh
script and with exec "$@"
you then pass the signals to the CMD
. (This means that you will have to use envsubst < /etc/nginx/conf.d/site.template > /etc/nginx/conf.d/default.conf
inside docker-entrypoint.sh
)
Dockerfile
docs: If you need to write a starter script for a single executable, you can ensure that the final executable receives the Unix signals by using exec
and gosu
commands...