Create a gist now

Instantly share code, notes, and snippets.

@cameron /init.sh
Last active Aug 29, 2015

initialize a CoreOS vm with the latest docker and DNS service discovery via skydock
This gist is old. Check out http://gijs.github.io/blog/2014/09/09/docker-and-service-discovery/
# install latest docker
wget --no-check-certificate https://get.docker.io/builds/Linux/x86_64/docker-latest -O docker
chmod +x docker
# systemd for the new docker
sudo tee /media/state/units/docker-local.service > /dev/null <<EOF
[Unit]
Description=docker local
[Service]
PermissionsStartOnly=true
ExecStartPre=/usr/bin/systemctl kill docker.service
ExecStart=/home/core/docker -dns 172.17.42.1 -H 0.0.0.0:4243 -H unix:///var/run/docker.sock -d
[Install]
WantedBy=local.target
EOF
# service discovery via dns
# https://github.com/crosbymichael/skydock
# http://www.asbjornenge.com/wwc/vagrant_skydocking.html
docker pull crosbymichael/skydns
docker pull crosbymichael/skydock
sudo tee /media/state/units/skydns.service > /dev/null <<EOF
[Unit]
Description=skydns
After=docker.service
Requires=docker-local.service
[Service]
ExecStartPre=/bin/sh -c '/home/core/docker rm skydns || ls > /dev/null'
ExecStart=/home/core/docker run -d -p 172.17.42.1:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain docker
ExecStop=/home/core/docker stop skydns
[Install]
WantedBy=local.target
EOF
sudo tee /media/state/units/skydock.service > /dev/null <<EOF
[Unit]
Description=skydock
After=docker.service
Requires=docker-local.service
[Service]
ExecStartPre=/bin/sh -c '/home/core/docker rm skydock || ls > /dev/null'
ExecStart=/home/core/docker run -d -v /var/run/docker.sock:/docker.sock --name skydock -link skydns:skydns crosbymichael/skydock -ttl 30 -environment dev -s /docker.sock -domain docker
ExecStop=/home/core/docker stop skydock
[Install]
WantedBy=local.target
EOF
# restart docker and dependent services
sudo systemctl restart local-enable.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment