Docker停止时,如果默认命令是一个shell脚本,则退出代码为-1。

3
我将在Docker中使用supervisord构建一个Tomcat容器。如果Dockerfile中的默认命令是:
CMD supervisord -c /etc/supervisord.conf

当我发送docker stop命令时,容器会成功退出并返回退出码0。
但是如果我有

的情况,容器则无法成功退出。
CMD ["/run"] 

并且在 run.sh 文件中,

supervisord -c /etc/supervisord.conf

使用docker stop命令时,我得到了退出码-1。查看日志,似乎supervisord没有收到指示退出请求的SIGTERM信号。

2014-10-06 19:48:54,420 CRIT Supervisor running as root (no user in config file)
2014-10-06 19:48:54,450 INFO RPC interface 'supervisor' initialized
2014-10-06 19:48:54,451 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2014-10-06 19:48:54,451 INFO supervisord started with pid 6
2014-10-06 19:48:55,457 INFO spawned: 'tomcat' with pid 9
2014-10-06 19:48:56,503 INFO success: tomcat entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

相对于之前的日志,它现在接收到 SIGTERM 信号后会优雅地退出。
2014-10-06 20:02:59,527 CRIT Supervisor running as root (no user in config file)
2014-10-06 20:02:59,556 INFO RPC interface 'supervisor' initialized
2014-10-06 20:02:59,556 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2014-10-06 20:02:59,557 INFO supervisord started with pid 1
2014-10-06 20:03:00,561 INFO spawned: 'tomcat' with pid 9
2014-10-06 20:03:01,602 INFO success: tomcat entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-10-06 20:05:11,690 WARN received SIGTERM indicating exit request
2014-10-06 20:05:11,690 INFO waiting for tomcat to die
2014-10-06 20:05:12,450 INFO stopped: tomcat (exit status 143)

需要帮助,请赐教。

谢谢, 卡迪克

更新:

supervisord.conf 文件

[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log

[program:mysql]
command=/usr/bin/pidproxy /var/run/mysqld/mysqld.pid /usr/bin/mysqld_safe --pid-file=/var/run/mysqld/mysqld.pid
stdout_logfile=/tmp/mysql.log
stderr_logfile=/tmp/mysql_err.log

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[unix_http_server]
file=/tmp/supervisor.sock ; path to your socket file

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

你能展示一下你的supervisord.conf文件的内容吗? - Thomasleveil
@Thomasleveil 我已经在问题中更新了supervisord文件。 - cucucool
1个回答

3
当您通过run.sh运行进程时,信号仅发送到该进程。除非您:

  1. 刻意使用trap向子进程发送信号
  2. 向进程组发送信号。
  3. 在run.sh中执行exec supervisord ...

否则子进程将无法收到信号。


我尝试使用exec supervisord,但退出代码仍然似乎是-1。 - cucucool

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接