Skip to content

Instantly share code, notes, and snippets.

@iboard
Last active October 14, 2020 12:44
Show Gist options
  • Save iboard/ef8a273e47496f590d2783c4b64e1224 to your computer and use it in GitHub Desktop.
Save iboard/ef8a273e47496f590d2783c4b64e1224 to your computer and use it in GitHub Desktop.
Start an NGINX-Docker-container to serve local html-files on a given port
#!/bin/sh
function syntax {
echo "NGINX CONTAINER"
echo ""
echo " Starts a docker container on a given port for a given html-root"
echo " directory. Andreas Altendorfer, 2020-10-14, Free Software."
echo ""
echo "Syntax:"
echo " nginx_container COMMAND NAME PORT HTML_PATH"
echo ""
echo "Commands:"
echo " start, stop, status"
echo ""
echo "Example:"
echo " nginx_container start mywiki 8888 /home/yours/doc/html"
echo " nginx_container stop mywiki 8888 /home/yours/doc/html"
echo " nginx_container status mywiki 8888 /home/yours/doc/html"
echo ""
exit 1
}
[ -z "$1" ] && syntax
COMMAND=$1
[ -z "$2" ] && syntax
NAME=$2
[ -z "$3" ] && syntax
PORT=$3
[ -z "$4" ] && syntax
HTML=$4
case $COMMAND in
start)
echo "Starting container $NAME, port $PORT, path $HTML"
docker run --name $NAME --rm \
-v $HTML:/usr/share/nginx/html:ro \
-p $PORT:80 \
-d nginx:mainline-alpine
;;
status)
echo "Status $NAME"
docker ps --filter="name=$NAME"
;;
stop)
echo "Stopping $NAME..."
docker stop $NAME
;;
*)
echo "Unknown command"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment