Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add tini as entrypoint in Dockerfile #570

Merged
merged 1 commit into from
Jan 14, 2025
Merged

Conversation

l0f3n
Copy link
Contributor

@l0f3n l0f3n commented Jan 12, 2025

I noticed that the docker container was slow to shut down, just a little over 10 seconds. This is a strong indication that the sigint signal is not getting forwarded to subprocesses properly, and the container only shuts down once it receives sigkill. This is easily fixed by using tini as the entrypoint, which will, among other things, handle the signals properly.

Here is an example before and after adding tini:
250112_12h22m07s_screenshot

Signed-off-by: Victor Löfgren <victor.lofgren99@pm.me>
@alexta69
Copy link
Owner

How does this work -- tini gets the signal, and forwards it to the process, if the process doesn't handle it (and keeps running) then aren't we left in the same situation? why is it shutting down when it gets the signal from tini, and doesn't if it gets the signal from docker?

@l0f3n
Copy link
Contributor Author

l0f3n commented Jan 12, 2025

I know nothing more than what I just read here: krallin/tini#8

But the gist of it is these few quotes (he is talking about Jenkins as an example):

Second, if Jenkins runs as PID 1, then it may not receive the signals you send it! That's a subtlety in PID 1. Unlike other unlike processes, PID 1 does not have default signal handlers, which means that if Jenkins hasn't explicitly installed a signal handler for SIGTERM, then that signal is going to be discarded when it's sent (whereas the default behavior would have been to terminate the process).

As to whether you should be using Tini. [...] Is whatever process you exec in your entrypoint registering signal handlers? A good way to figure this out might be to check whether your process responds properly to e.g. docker stop (or if it waits for 10 seconds before exiting)

So I guess another way to fix this is to add explicit signal handlers, but why bother?

@alexta69 alexta69 merged commit a61737d into alexta69:master Jan 14, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants