Created
June 17, 2014 01:58
-
-
Save cjlyth/ed53bb60f4ee82e7aca8 to your computer and use it in GitHub Desktop.
This gist can be used to serve a directory using the http-server nodejs module
This file contains 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
#!/usr/bin/env bash | |
DATA_DIR="$( cd ${1:-.} && pwd )" | |
[[ -d "${DATA_DIR?}" ]] || { | |
echo "Unable to find directory: ${DATA_DIR}" | |
exit 1 | |
} | |
CONTAINER_NAME="$(basename ${2:-${DATA_DIR}})" | |
docker restart ${CONTAINER_NAME?} &> /dev/null && { | |
echo "Docker container '${CONTAINER_NAME}' restarted" | |
} || { | |
echo "Running docker image 'cjlyth/http-server' as '${CONTAINER_NAME}'" | |
docker run -d -P \ | |
--name="$CONTAINER_NAME" \ | |
-v $DATA_DIR:/data \ | |
cjlyth/http-server || { | |
docker stop $CONTAINER_NAME | xargs --no-run-if-empty docker rm | |
exit 2 | |
} | |
} | |
docker port $CONTAINER_NAME 8080 | xargs --no-run-if-empty -I{} xdg-open http://{} 1>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment