Skip to content

Instantly share code, notes, and snippets.

@wgbartley wgbartley/launch_webs.sh
Last active Aug 29, 2015

Embed
What would you like to do?
Docker web container launcher
#!/bin/bash
for d in $(find www-enabled/ -mindepth 1 -maxdepth 1 -type l); do
bn=`basename $d`
aliases_arr=($bn)
aliases_i=1
# Check if the container is already running
is_running=`docker ps -f status=running | grep "$bn" | wc -l`
# Get aliases
if [ -f "$d/.www_aliases" ]; then
while read a; do
if [ "$a" != "" ]; then
aliases_arr[aliases_i]=$a
aliases_i=$(($aliases_i + 1))
fi
done < "$d/.www_aliases"
fi
# Auto-set non-www alias (if www is present)
if [ "${bn:0:4}" == "www." ]; then
aliases_arr[aliases_i]=${bn:4}
aliases_i=$(($aliases_i + 1))
fi
# Implode aliases_arr
aliases_str=""
count=0
while [ "x${aliases_arr[count]}" != "x" ]; do
aliases_str="$aliases_str,${aliases_arr[$count]}"
count=$(( $count + 1 ))
done
aliases="${aliases_str:1}"
# If it's not already running . . .
if [ $is_running -eq 0 ]; then
# Launch it!
echo ">> Launching $bn . . ."
docker run -d \
-e VIRTUAL_HOST="$aliases" \
--name "$bn" \
-v $(pwd)/$d:/var/www/html \
--link mysql:mysql \
-p 80 \
php:5.6-apache
else
echo ">> Already running $bn!"
fi
done
@acofer

This comment has been minimized.

Copy link

acofer commented Jul 13, 2015

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.