envd icon indicating copy to clipboard operation
envd copied to clipboard

feat(docker): init process to manage multiple processes

Open gaocegege opened this issue 3 years ago β€’ 11 comments

Description

Now we run sshd, jupyter and some other background processes in the container. We need to have a init process to manage them

gaocegege avatar May 07 '22 07:05 gaocegege

/assign

gaocegege avatar May 17 '22 06:05 gaocegege

Ref https://ahmet.im/blog/minimal-init-process-for-containers/

  • supervisord
  • tini
  • dumb-init

gaocegege avatar May 17 '22 06:05 gaocegege

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 avatar May 17 '22 06:05 kemingy

@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/

gaocegege avatar May 17 '22 06:05 gaocegege

https://circus.readthedocs.io/en/latest/

@Zheaoli recommends this project, too.

gaocegege avatar May 17 '22 06:05 gaocegege

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.

gaocegege avatar May 17 '22 07:05 gaocegege

The approach above LGTM now since we do not need a graceful shutdown.

gaocegege avatar May 17 '22 07:05 gaocegege

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

VoVAllen avatar May 17 '22 08:05 VoVAllen

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.

gaocegege avatar May 17 '22 08:05 gaocegege

I'm not so familiar with this part. Is entrypoint the same as the PID 1 process?

VoVAllen avatar May 17 '22 10:05 VoVAllen

Yes, the entrypoint is the PID 1 process

gaocegege avatar May 17 '22 14:05 gaocegege

I think we can close the issue.

gaocegege avatar Aug 12 '22 07:08 gaocegege