docker-wait
is a pre-startup hook for docker containers
Within the scripts, these container attributes are provided via environment variables:
- container's hostname, labels, image name, image.
- path to container's root filesystem.
- container's network namespace which you can access by
ip netns exec $CONTAINER_NET_NS <cmd>
.
You can do whatever needed to init or validate a container's runtime environment before its entrypoint/command starts, include but not limited to:
- validate the checksum of a specific path inside the container.(see example)
- add some iptables rule to the container's network namespace.
- decrept secret data inside the container with a private key installed on the host.
see example.
- specify container' entrypoint to a customized golang program named dwait via
docker run -v /usr/lib/dwait:/d -v /var/run/dwait/:/.dwait --entrypoint /d/dwait
. - dwait POST a HTTP request over unix socket to dresponse-a service running on the host.
- dresponse execute all prestart hooks for the container and return the container's command and image entrypoint via HTTP response.
- dwait read and parse the actual entrypoint and command from the HTTP response body, and launch them with a
exec
system call.