Last active
May 8, 2018 19:36
-
-
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
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
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