Skip to content

Instantly share code, notes, and snippets.

@horodchukanton
Last active May 8, 2018 19:36
Show Gist options
  • Save horodchukanton/0dfb439cfa16d9819855b5eb7b580949 to your computer and use it in GitHub Desktop.
Save horodchukanton/0dfb439cfa16d9819855b5eb7b580949 to your computer and use it in GitHub Desktop.
Adds a function to ~/.bashrc to run nginx docker container with root in given directory
RC_FILE=~/.bashrc
PORT=8080
NAME=nginx
# Check function is already defined
grep 'servedir' $RC_FILE > /dev/null && (echo "Function definition already exists in $RC_FILE" && exit);
read -d '' func <<- FUNCTION
servedir() {
docker stop $(docker ps -f Name=${NAME} -q)
DIR=$1
docker run -d -p${PORT}:80 --name=${NAME} --mount "type=bind,source=${DIR},target=/usr/share/nginx/html" nginx || exit
echo "Server is running on port ${PORT}"
}
FUNCTION
echo "$func" >> $RC_FILE
source $RC_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment