Testing Compose + Swarm + Machine to start up jwilder/nginx-proxy
fronting jwilder/whoami
.
Last active
February 28, 2024 04:51
-
-
Save md5/38b0db36267a9456a840 to your computer and use it in GitHub Desktop.
jwilder/nginx-proxy using Compose + Swarm + Machine
This file contains hidden or 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
/*.env |
This file contains hidden or 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 | |
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 | |
) |
This file contains hidden or 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
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 |
This file contains hidden or 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 | |
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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this was really helpful thanks!