问题描述
我的自定义docker-compose命令不会正常停止。为什么以下内容不起作用,如何正确修复(即没有SIGKILL)?
-
文档中提到了这一点:https://docs.docker.com/compose/faq
-
类似的问题(没有帮助-参见下面的测试):
Docker: gracefully stop django server
How to gracefully stop a Dockerized Python ROS2 node when run with docker-compose up?
我编写了这些测试来演示:
version: '3.3'
services:
# My personal use case
test1_string:
image: python:3.9.0rc1-alpine3.12
command: 'python -u -m smtpd -n -c DebuggingServer 0.0.0.0:1025'
# https://docs.docker.com/compose/faq/
# "Compose always uses the JSON form,so don’t worry if you override the command or entrypoint in your Compose file."
test2_list:
image: python:3.9.0rc1-alpine3.12
command: ['python','-u','-m','smtpd','-n','-c','DebuggingServer','0.0.0.0:1025']
# Maybe it's an issue with networking and syscalls?
# Using nc once for a comparison to smtpd DebuggingServer above
test3_bash:
image: bash:5.0.18
command: ['bash','nc -k -l 4444 > filename.out']
# Something simpler,just a sleep.
test4_bash_sleep:
image: bash:5.0.18
command: ['bash','sleep 100']
# Apparently bash doesn't forward signals,but exec can help (?)
test5_bash_exec:
image: bash:5.0.18
command: ['bash','exec sleep 100']
# Print any signals sent to the executable
test6_bash_trap:
image: bash:5.0.18
command: ['bash','for s in HUP INT TERM KILL EXIT ; do trap "echo $$s; exit 0" $$s ; done ; sleep 100']
# Finally,use SIGKILL instead of SIGTERM. This works,but is overkill and not at all graceful.
test7_kill:
image: python:3.9.0rc1-alpine3.12
command: ['python','0.0.0.0:1025']
stop_signal: SIGKILL
这是输出,启动后按Ctrl-C:
$ docker-compose --version
docker-compose version 1.25.4,build unkNown
$ docker --version
Docker version 19.03.11,build 42e35e6
$ docker-compose up
Creating docker_stop_test2_list_1 ... done
Creating docker_stop_test1_string_1 ... done
Creating docker_stop_test6_bash_trap_1 ... done
Creating docker_stop_test4_bash_sleep_1 ... done
Creating docker_stop_test7_kill_1 ... done
Creating docker_stop_test5_bash_exec_1 ... done
Creating docker_stop_test3_bash_1 ... done
Attaching to docker_stop_test4_bash_sleep_1,docker_stop_test5_bash_exec_1,docker_stop_test2_list_1,docker_stop_test3_bash_1,docker_stop_test6_bash_trap_1,docker_stop_test7_kill_1,docker_stop_test1_string_1
^CGracefully stopping... (press Ctrl+C again to force)
Stopping docker_stop_test5_bash_exec_1 ...
Stopping docker_stop_test3_bash_1 ...
Stopping docker_stop_test6_bash_trap_1 ...
Stopping docker_stop_test7_kill_1 ... done
Stopping docker_stop_test1_string_1 ...
Stopping docker_stop_test2_list_1 ...
Stopping docker_stop_test4_bash_sleep_1 ...
test7_kill
是唯一一个停止使用但使用SIGKILL的程序。我该如何使其他任何一个正常工作?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)