#经过测试,不能使用 ENTRYPOINT ["/modapi/modapi", "1>> /dev/null","2>> ./logs/stderr.log"],原因是虽然这种方案可以 #保证modapi命令为1号程序,能够接收到os的signal信号。但是如果程序core了,会直接导致1号进程core。则docker直接退出并且错误没有写入到 #stderr.log文件中。因此通过start.sh传递terminated信号,同时可以保证core时候堆栈信息可以写入到stderr.log中 CMD ["/bin/sh", "/modapi/start.sh"]
#!/bin/sh # Define function to forward signals term_handler() { echo "Forwarding SIGTERM to child process" kill -TERM "$child_pid" wait "$child_pid" } # Trap signals trap term_handler SIGTERM # Start the child process /modapi/modapi 1>> /dev/null 2>> /modapi/logs/stderr.log & child_pid=$! # Wait for the child process to exit wait "$child_pid"