envd
envd copied to clipboard
feat(docker): init process to manage multiple processes
Description
Now we run sshd, jupyter and some other background processes in the container. We need to have a init process to manage them
/assign
Ref https://ahmet.im/blog/minimal-init-process-for-containers/
- supervisord
- tini
- dumb-init
Some articles:
- https://manjusaka.itscoder.com/posts/2021/02/13/a-simple-introduction-about-the-init-process-in-container/
- https://manjusaka.itscoder.com/posts/2021/02/27/damn-the-init-process/
@kemingy Thanks! The world is small. I am talking with @Zheaoli (Manjusaka) about this problem on WeChat.
Some articles:
- https://manjusaka.itscoder.com/posts/2021/02/13/a-simple-introduction-about-the-init-process-in-container/
- https://manjusaka.itscoder.com/posts/2021/02/27/damn-the-init-process/
https://circus.readthedocs.io/en/latest/
@Zheaoli recommends this project, too.
https://ahmet.im/blog/minimal-init-process-for-containers/
tini + bash 4.x
This is not a complete solution, but gets the job done if you donβt care about graceful termination (through signal forwarding to children).
Since tini(1) alone is not capable of running multiple child processes, bash
gives us an escape hatch: Have a bash script entrypoint where you start
processes in the background and exit immediately when one of the background
processes terminate using the bash 4.x builtin wait -n command:
#!/usr/bin/env bash
set -e
program1 &
program2 &
wait -n
Then in your Dockerfile, modify the entrypoint:
ENTRYPOINT ["/bin/tini", "--", "entrypoint.sh"]
Pros:
- simple, tini(1) is container-optimized and small, handles zombie reaping etc.
- easily terminates when a child process exits (while preserving exit code)
Cons:
- no signal forwarding: your container will still exit, but you lose the graceful termination opportunity.
- you have to write a small custom bash script entrypoint and ship bash 4.x
- similarly, when a subprocess terminates, the other process will not get a graceful termination notice as bash will just exit.
The approach above LGTM now since we do not need a graceful shutdown.
Actually I'm thinking of that the entrypoint of container will also be able to parse the envd file. Thus we can support the grammar like https://github.com/tensorchord/envd/issues/91#issuecomment-1127442410. Not sure how much is this related to the initd process
the entrypoint of container will also be able to parse the envd file
Can you please explain more about it?
According to discussion #91, I think we need to support the approach to exec commands in the container. And this issue is to design a mechanism to manage our daemon processes like jupyter notebook server and ssh server.
They are slightly different. #91 is to support exec during runtime, this issue is to support multi daemon process in the container.
I'm not so familiar with this part. Is entrypoint the same as the PID 1 process?
Yes, the entrypoint is the PID 1 process
I think we can close the issue.