简体   繁体   English

停止Docker容器时是否可以运行命令?

[英]Is it possible to run a command when stopping a Docker container?

I'm using docker-compose to organize containers for a JS application. 我正在使用docker-compose来组织JS应用程序的容器。
The source container sports command: npm start , pretty standard, to spin up the live application. 源容器command: npm start ,非常标准,以启动实时应用程序。 However, that timeouts when I ask it to stop. 但是,当我要求它停止时会超时。

I was wondering if it's possible to have docker-compose stop to run a command inside the container - that could properly terminate the application. 我想知道是否有可能使docker-compose stop在容器内运行命令-可以正确终止应用程序。

docker-compose stop just sends a SIGTERM to your container and if it does not stop after 10secs (configurable) SIGKILL follows. docker-compose stop只是将SIGTERM发送到您的容器,如果它在10秒(可配置)后仍未停止,则会执行SIGKILL So if you want to customize this behavior, you should handle signal inside your entrypoint (if you have one). 因此,如果要自定义此行为,则应在entrypoint内部处理信号(如果有的话)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM