Skip to content

Instantly share code, notes, and snippets.

@md5 md5/.gitignore
Last active Aug 16, 2018

Embed
What would you like to do?
jwilder/nginx-proxy using Compose + Swarm + Machine

Testing Compose + Swarm + Machine to start up jwilder/nginx-proxy fronting jwilder/whoami.

#!/bin/bash
set -e
if [ -z "$DIGITALOCEAN_ACCESS_TOKEN" ]; then
echo >&2 "ERROR: You must export DIGITALOCEAN_ACCESS_TOKEN"
exit 1
fi
docker pull swarm > /dev/null
TOKEN="$(docker run swarm create)"
echo >&2 "Docker Swarm token: $TOKEN"
echo >&2 "Creating Docker Swarm cluster"
(
set -x
docker-machine create -d digitalocean --swarm --swarm-master --swarm-discovery "token://$TOKEN" swarm-master
docker-machine create -d digitalocean --swarm --swarm-discovery "token://$TOKEN" --engine-label type=app swarm-app-01
docker-machine create -d digitalocean --swarm --swarm-discovery "token://$TOKEN" --engine-label type=app swarm-app-02
docker-machine create -d digitalocean --swarm --swarm-discovery "token://$TOKEN" --engine-label type=app swarm-app-03
docker-machine create -d digitalocean --swarm --swarm-discovery "token://$TOKEN" --engine-label type=proxy swarm-proxy
)
app:
image: jwilder/whoami
ports:
- "8000:8000"
env_file:
- app.env
proxy:
image: jwilder/nginx-proxy
ports:
- "80:80"
volumes:
- "/tmp/docker-certs:/tmp/docker-certs"
env_file:
- proxy.env
#!/bin/bash
set -e
echo >&2 "Generating app.env:"
cat <<EOF | tee app.env >&2
VIRTUAL_HOST=$(docker-machine ip swarm-proxy)
constraint:type==app
EOF
echo >&2 "Generating proxy:"
cat <<EOF | tee proxy.env >&2
DOCKER_TLS_VERIFY=1
DOCKER_HOST=tcp://$(docker-machine ip swarm-master):3376
DOCKER_CERT_PATH=/tmp/docker-certs
constraint:type==proxy
EOF
eval "$(docker-machine env --swarm swarm-master)"
echo >&2 "Copying TLS config to swarm-proxy"
docker-machine scp -r "$DOCKER_CERT_PATH" swarm-proxy:/tmp/docker-certs
echo >&2 "Starting services via Docker Compose"
docker-compose up -d
docker-compose scale proxy=1 app=3
echo >&2 "Checking running containers"
docker ps
echo >&2 "Visit http://$(docker-machine ip swarm-proxy) to test"
@bhurlow

This comment has been minimized.

Copy link

bhurlow commented Oct 17, 2015

this was really helpful thanks!

@md5

This comment has been minimized.

Copy link
Owner Author

md5 commented Oct 21, 2015

@bhurlow 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.