Created
June 23, 2016 13:19
-
-
Save swade1987/798c7ad123a799c8aa756477db77f3b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Remove docker engine key to make it unique | |
sudo rm -f /etc/docker/key.json | |
sudo service docker restart | |
# Configure the docker daemon | |
sudo mkdir /etc/systemd/system/docker.service.d | |
cat << "EOF" > /etc/systemd/system/docker.service.d/daemon.conf | |
{ | |
[Service] | |
ExecStart= | |
ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2375 -H unix:// --cluster-store=consul://${consul_server} --cluster-advertise=eth0:2375 | |
} | |
EOF | |
# Restart the docker daemon | |
sudo systemctl daemon-reload | |
sudo systemctl restart docker | |
# Obtain the private IP address of this instance via the AWS API. | |
readonly EC2_METADATA_URL='http://169.254.169.254/latest/meta-data' | |
HOST_IP=$$(curl -s $${EC2_METADATA_URL}/local-ipv4) | |
# Create a swarm manager container and connect it to Consul. | |
docker run -d \ | |
--name swarm \ | |
-p 80:80 \ | |
swarm manage \ | |
-H tcp://0.0.0.0:80 \ | |
--replication \ | |
--advertise $${HOST_IP}:80 consul://${consul_server} | |
# Create an overlay network for our environment | |
docker network create --driver overlay --subnet=${subnet} ${overlay_network_name} | |
echo 'Completed.' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Remove docker engine key to make it unique | |
sudo rm -f /etc/docker/key.json | |
sudo service docker restart | |
# Configure the docker daemon | |
sudo mkdir /etc/systemd/system/docker.service.d | |
cat << "EOF" > /etc/systemd/system/docker.service.d/daemon.conf | |
{ | |
[Service] | |
ExecStart= | |
ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2375 -H unix:// --cluster-store=consul://${consul_domain_name} --cluster-advertise=eth0:2375 | |
} | |
EOF | |
# Restart the docker daemon | |
sudo systemctl daemon-reload | |
sudo systemctl restart docker | |
# Obtain the private IP address of this instance via the AWS API. | |
readonly EC2_METADATA_URL='http://169.254.169.254/latest/meta-data' | |
HOST_IP=$$(curl -s $${EC2_METADATA_URL}/local-ipv4) | |
# Hook up a Swarm container to interact with the Swarm Master. | |
sudo docker run -d \ | |
--name=swarm-agent \ | |
--restart=always \ | |
swarm \ | |
join \ | |
--advertise=$${HOST_IP}:2375 \ | |
consul://${consul_domain_name} | |
# Hook up a Registrator container to interact with Consul. | |
sudo docker run -d \ | |
--name=registrator \ | |
--restart=always \ | |
--net=host \ | |
--volume=/var/run/docker.sock:/tmp/docker.sock \ | |
gliderlabs/registrator \ | |
consul://${consul_domain_name} | |
# Hook up a Traefik container to interact with Swarm. | |
sudo docker run -d \ | |
-p 80:80 \ | |
-p 8080:8080 \ | |
--name=traefik \ | |
--net=${environment} \ | |
traefik \ | |
-l DEBUG \ | |
-c /dev/null \ | |
--docker \ | |
--docker.domain=${environment_subdomain} \ | |
--docker.endpoint=tcp://${swarm_domain_name}:80 \ | |
--docker.watch \ | |
--web | |
echo 'Completed...' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment