Skip to content

Instantly share code, notes, and snippets.

@tad-lispy
Created May 3, 2014 12:42
Show Gist options
  • Save tad-lispy/bf262b16de6ffed260fa to your computer and use it in GitHub Desktop.
Save tad-lispy/bf262b16de6ffed260fa to your computer and use it in GitHub Desktop.
Docker + SkyDNS + Upstart
# Docker Upstart and SysVinit configuration file
# Customize location of Docker binary (especially for development testing).
#DOCKER="/usr/local/bin/docker"
# Use DOCKER_OPTS to modify the daemon startup options.
DOCKER_OPTS="-r=false --dns 172.17.42.1 --dns 8.8.8.8 --dns 8.8.4.4"
# If you need Docker to use an HTTP proxy, it can also be specified here.
#export http_proxy="http://127.0.0.1:3128/"
# This is also a handy place to tweak where Docker's temporary files go.
#export TMPDIR="/mnt/bigdrive/docker-tmp"
description "Docker daemon"
start on filesystem
stop on runlevel [!2345]
limit nofile 524288 1048576
limit nproc 524288 1048576
respawn
pre-start script
# see also https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mount
if grep -v '^#' /etc/fstab | grep -q cgroup \
|| [ ! -e /proc/cgroups ] \
|| [ ! -d /sys/fs/cgroup ]; then
exit 0
fi
if ! mountpoint -q /sys/fs/cgroup; then
mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
fi
(
cd /sys/fs/cgroup
for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do
mkdir -p $sys
if ! mountpoint -q $sys; then
if ! mount -n -t cgroup -o $sys cgroup $sys; then
rmdir $sys || true
fi
fi
done
)
end script
script
# modify these in /etc/default/$UPSTART_JOB (/etc/default/docker)
DOCKER=/usr/bin/$UPSTART_JOB
DOCKER_OPTS=
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
exec "$DOCKER" -d $DOCKER_OPTS
end script
post-start script
# Emit custom event to initialize Skydock DNS
echo "Docker spawned"
exec initctl emit docker-spawned
end script
description "Start docker dns service. See: https://github.com/crosbymichael/skydock"
author "Tadeusz Łazurski"
start on starting docker-skydock
respawn
console log
script
echo "Starting skydns container"
exec docker start -a skydns
end script
post-start script
# Try to query our DNS service 20 times with 1s timeout.
# Consider our service to be running when we get any response.
dig @172.17.42.1 +short +time=1 +tries=20 '*'
end script
description "Start skydock service. See: https://github.com/crosbymichael/skydock"
author "Tadeusz Łazurski"
start on docker-spawned # Custom event. See docker.conf post-start script.
respawn
console log
script
echo "Starting skydock container"
exec docker start -a skydock
end script
post-start script
# Delay `started` event.
# Is there a better way to ensure skydock is initialized before starting other containers?
sleep 2
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment