dock
is a "micro init system" for linux containers
curl -sL https://github.com/robinmonjo/dock/releases/download/v0.1/dock-v0.1.tgz | tar -C /usr/local/bin -zxf -
This will place the latest dock
binary in /usr/local/bin
dock
acts as the PID 1 in the container. It forwards every signals to it's child process. When a child process dies, dock
:
- detect one of its child died
- send SIGTERM to all processes remaining in its process tree
- call
wait4
until no more children exist
Step 3 may block if some processes do not respond to the SIGTERM in step 2. If this is the case, a SIGKILL is sent after the SIGTERM (within a 5 seconds timeout)
dock
is written in Go and has 0 dependency. The binary can simply be added into a linux container image. It also provides some useful features :
- can call a web hook when process state changes (
starting
,running
andcrashed
) - can say a process started only when a given port is bound (if you start a web server, you may want to know when this one is ready to accept connections), using this Go profcs package
- smart stdin / stdout (see the
--io
flag for more information) - can provide log rotation (see
--log-rotate
flag for more information)
dock [OPTIONS] command
Allows to redirect process stdin / stdout:
dock bash
run bash with current stdin and stdoutdock --io file:///var/run/process.log server.go
redirect stdout to the given file. Stdin stay unchangeddock --io tcp://192.168.1.9:2567 bash
make stdin and stdout go over a tcp connectiondock --io tls://192.168.1.9:2657 bash
make stdin and stdout go over a tls connection
Every URL scheme supported by Go's net.Dial
are supported by dock
If specified, dock
performs a HTTP PUT request with the JSON payload:
{
"ps": {
"status": "<status>"
}
}
where <status>
may be: starting
, running
or crashed
. Note that if --bind-port
flag is used, the running
status is sent only once the given port is bound by one of dock
children processes
Port dock
's child process is expected to bind. Port may be bound by a descendant of dock
(not only its direct child). This flag is useful only when the --web-hook
flag is used.
If given --io
is a file, specifying -log-rotate X
perform a log rotation every X hours:
- archive (gzip) the current log file by prepending a timestamp (in the stdout file directory)
- empty the current log file
- keep at most 5 log archives
Add a prefix to stdout lines. Format: prefix[:<color>]
where color may be white, green, blue, magenta, yellow, cyan or red
- use the Makefile and Dockerfile :)
- use the
-d
flag for verbosity - the
utils.go
file contains some nice function to inspect and debug
- actually implement the kill timeout as it is documented :)
- check if err on start is a wait status and if so, return the exit code (i.e: 127 path not found)
- test port binding with
nc
and see why this ? - fix log rotate test that fails regularly
- more tests !
- stdout prefix + coloring only available over network but sometimes prefix get written at the end of a line
- process is not stopped if interactive and over the network and the connection is closed