Skip to content

Instantly share code, notes, and snippets.

@cyppst
Forked from swade1987/manager user-data
Created November 4, 2018 19:41
Show Gist options
  • Save cyppst/00ac5f91b6476171f5619cb0b18aa2c3 to your computer and use it in GitHub Desktop.
Save cyppst/00ac5f91b6476171f5619cb0b18aa2c3 to your computer and use it in GitHub Desktop.
#!/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.'
#!/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