Skip to content

Instantly share code, notes, and snippets.

@tcoupin
Created November 22, 2016 08:49
Show Gist options
  • Save tcoupin/f6bf31549a9084188bc308171690234b to your computer and use it in GitHub Desktop.
Save tcoupin/f6bf31549a9084188bc308171690234b to your computer and use it in GitHub Desktop.
Script to launch httpd on a path using docker
#!/bin/bash
if [[ "$1" == "-h" || "$1" == "--help" ]]
then
echo "Usage: $(basename $0) [foldertoserve]";
echo " - foldertoserve can be relative or absolute"
echo " - if no foldertoserve, just stop containers"
exit 0
fi
function stop(){
echo "Stopping old containers"
(docker ps -f label=serveHTTP -q | xargs docker kill) > /dev/null 2>&1 || true
(docker ps -f label=serveHTTP -q -a | xargs docker rm) > /dev/null 2>&1 || true
}
function start(){
echo "Starting container"
docker run -d --name httpd-$(basename $1) -v $1:/usr/local/apache2/htdocs/ --label serveHTTP -p 80:80 httpd:alpine || docker rm httpd-$(basename $1)
}
stop;
if [[ "$1" == "" ]];then exit 0;fi
if [[ $1 == /* ]];then target=$1; else target=$PWD/$1;fi
start $target && echo "Listen on 0.0.0.0:80"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment