Skip to content

Instantly share code, notes, and snippets.

@hmalphettes
Created November 24, 2014 07:51
Show Gist options
  • Save hmalphettes/dca6ca71effdb5ccd186 to your computer and use it in GitHub Desktop.
Save hmalphettes/dca6ca71effdb5ccd186 to your computer and use it in GitHub Desktop.
setup and run the dockerized virtual hosting demo
# Builds the goodbye world nodejs app
FROM google/nodejs-runtime
#!/bin/bash
# https://speakerdeck.com/hmalphettes/simple-virtual-hosts-for-docker-containers
docker ps -a --no-trunc | grep 'Exit' | awk '{print $1}' | xargs -r docker rm;
# Run the load balancer if it is not running already
docker ps | grep -w loadbalancer;
if [ ! "$?" -eq "0" ]; then
docker run \
--name loadbalancer \
--detach \
--restart=always \
-p "80:80" \
-v /var/run/docker.sock:/tmp/docker.sock \
jwilder/nginx-proxy
fi
# Run the dynamic DNS
docker ps | grep -w route53;
if [ ! "$?" -eq "0" ]; then
echo "Start route53"
source $HOME/docker-scripts/secrets
PUBLIC_IP=$(ip -o addr show | grep docker0 | grep inet\ | awk '/inet/ {print $4}' | cut -d'/' -f1)
docker run --name route53 \
--detach=true \
--restart=on-failure:5 \
-v /var/run/docker.sock:/tmp/docker.sock \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
-e PUBLIC_IP=$PUBLIC_IP \
hmalphettes/docker-route53-dyndns
fi
# Run hello if it is not running already
docker ps | grep -w hello;
if [ ! "$?" -eq "0" ]; then
echo "Starting hello"
docker run \
--name hello \
--detach \
--restart=always \
-p "8080:8080" \
-e VIRTUAL_HOST=hello.stoic.cc \
google/nodejs-hello
fi
docker ps | grep -w goodbye;
if [ ! "$?" -eq "0" ]; then
echo "Starting goodbye"
docker run \
--name goodbye \
--detach \
--restart=always \
-p "8081:8080" \
-e VIRTUAL_HOST=goodbye.stoic.cc \
hugues/nodejs-goodbye
fi
# AWS credentials
AWS_ACCESS_KEY_ID=NOT_AN_ACCESS_KEY
AWS_SECRET_ACCESS_KEY=NOT_THE_REAL_SECRETE_ACCESS_KEY
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.send('Goodbye World');
});
var server = app.listen(8080, function() {
console.log('Listening on port %d', server.address().port);
});
@hmalphettes
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment