Skip to content
minimalist init implementation for containers
Branch: master
Clone or download
chazomaticus Slight code tweak
I liked it better this way, no biggz.
Latest commit ae12b9d Jan 17, 2017

README.md

Minit

Minit is a minimalist init implementation designed for use inside containers, for instance as the root process in a Docker image.

https://github.com/chazomaticus/minit

Use

There are three ways to start using minit inside your container. The easiest, assuming you're using Docker, is to simply use one of the minit base images as a base for your own Docker image. See the example directory.

If your container will be running Ubuntu, you can also make use of the minit PPA to avoid building minit yourself. For another Docker example:

# This is roughly equivalent to add-apt-repository ppa:chazomaticus/minit.
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E007F6BD
RUN echo "deb http://ppa.launchpad.net/chazomaticus/minit/ubuntu quantal main" > /etc/apt/sources.list.d/minit.list

RUN apt-get update && apt-get upgrade -y && apt-get install -y minit # etc.

Lastly, you can simply build minit by running make (or otherwise compiling the .c file into an executable). Put the resulting executable in your container's filesystem and set it to run as the root process when your container starts.

Note that in Docker, you need to use an exec form of ENTRYPOINT or CMD, as opposed to a shell form to run minit. See for example the ENTRYPOINT docs. The minit base images set this up for you automatically.

Operation

When minit starts, it runs a startup process which defaults to /etc/minit/startup. When it's shutting down, minit runs a shutdown process which defaults to /etc/minit/shutdown. Minit will shut down for any of three reasons: minit receives SIGTERM or SIGINT (the latter for convenience when running in the foreground), the startup process exits with nonzero status, or minit is out of child processes. The shutdown process executes exactly once, regardless of the reason. After the shutdown process exits, minit will issue SIGTERM to all remaining processes, unless it's running as a normal, non-init process. Minit exits, with the status returned from the startup process, when there are no more child processes (including the shutdown process).

You can override the default startup and shutdown processes with command line arguments to minit: the first, if non-empty, specifies the path to the startup process, and the second, the shutdown process. Note that it's not possible to pass command line arguments to either process. However, minit's environment is passed unmolested, so you can pass data there.

Minit doesn't forward any signals (other than sending SIGTERM to every process, potentially as a result of receiving SIGTERM itself, when shutting down as described above).

Justification

If you need more than one process inside your container, it's important for the root process to behave like init(8). See baseimage-docker for a thorough explanation of what that means and the special considerations for init inside Docker. Minit solves the init problem in a dead-simple way.

Docker recommends running Supervisor as your container's root process if you need to start multiple services inside a single container. Sometimes, though, you don't want the overhead of a full Python stack tagging along with your nice clean container image.

Advantages vs. Supervisor:

  • No dependencies
  • Smaller (only about 11K in size vs. about 18M for Python and Supervisor reported by apt-get on a clean Trusty image)
  • Allows arbitrary commands in container startup and shutdown
  • Easier to control daemons that can't run in the foreground like Postfix

Disadvantages vs. Supervisor:

  • Doesn't monitor or restart services

Advantages vs. baseimage-docker:

  • Simpler to use
  • Easier to control exactly which services get started
  • Smaller (a Trusty image with minit added is about 275M vs. about 346M for baseimage-docker)
  • Works on any distro, not just Ubuntu

Disadvantages vs. baseimage-docker:

  • Doesn't automatically run all the services they deem essential

Similar Projects

Yelp came out with a project similar to minit a while back now called dumb-init. I haven't looked too closely at it, but here are what I've gathered the differences to be:

  • Dumb-init seems more oriented toward a single child process model, as evidenced by needing to specify it, args and all, on the command line. Minit executes startup and shutdown scripts that more easily allow control of any number of running processes.
  • Dumb-init forwards signals; minit doesn't. Kind of makes sense given the first point.

Otherwise, I think they're very similar.

Enjoy!

Thanks to Arachsys init for ideas and inspiration. Thanks to Ricardo Branco for their contributions.

You can’t perform that action at this time.