Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[UPDATE]: add a minimal reproducible example #294

Closed
wants to merge 1 commit into from
Closed

[UPDATE]: add a minimal reproducible example #294

wants to merge 1 commit into from

Conversation

codespearhead
Copy link

@codespearhead codespearhead commented Feb 7, 2023

Add a MRE of the problem mentioned in the very first bullet-point of section "Why you need an init system", which can be solved by using dumb-init in the Dockerfile

@codespearhead
Copy link
Author

@asottile I updated the previous message for clarity's sake.

@polarathene
Copy link

Your minimal example is not really minimal?

Here you go (no need for NodeJS, that JS is effectively just doing sleep, but with a visual countdown):

# CTRL+C will not stop the process exiting the container:
docker run --rm alpine sleep 30

# CTRL+C will now stop the container immediately (`--init` uses built-in `tini`):
docker run --rm -init alpine sleep 30
  • The command sleep is PID 1, and PID 1 does not setup default signal handlers, so if your process does not take care of that it'll ignore the signal SIGINT sent via CTRL+C. If you want to immediately exit CTRL+\ will send SIGQUIT which is more akin to SIGKILL, but will often output a core dump with it.
  • Likewise, if your PID 1 runs a child process, it'll not forward signals received by default (for a shell script you can use exec command-here, which will make the new command PID 1).
    • However within a container, when PID 1 exits, the container does so it'll bring down any child processes with it. dumb-init defaults to forwarding to an entire process group (if the README example with sleep is not helpful, you can see another comparison demonstrated here).
    • If you don't forward signals, those child processes cannot handle them for a graceful shutdown for example. PID 1 may only receive them and not do anything actionable or desired as a result.

This is just a signal handling example, not handling zombie processes.

@polarathene polarathene mentioned this pull request Mar 11, 2024
@codespearhead codespearhead closed this by deleting the head repository Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants