Last active
August 29, 2015 14:08
-
-
Save wgbartley/f18428e15f614eb1835e to your computer and use it in GitHub Desktop.
Docker web container launcher
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://docs.docker.com/compose/