Make your docker container run forever with the ability to gracefully stop

I am trying to create a docker container. He must run forever in the background. But whenever I press Ctrl + C or docker stop, it should close without wasting time.

My current code

#RUN trap 'echo $excode' EXIT HUP INT QUIT PIPE TERM
ENTRYPOINT while :; do read; done
#ENTRYPOINT trap "exit 1" SIGTERM SIGHUP && tail -f /dev/null & wait && exit 0

I can make it work forever, but for some reason my script does not receive TRAP events. Any clue how to fix it.

+4
source share
2 answers

You might consider using (with docker 1.9+) STOPSIGNALin a Docker file.

STOPSIGNAL , .
, syscall , 9, SIGNAME, SIGKILL.

script . "" Docker" program.sh -PID1.

+4

: -t -i:

docker run -it --name=<container_name> <image>:<tag>

ctrl+c

.

0

Source: https://habr.com/ru/post/1660774/


All Articles