Last active
June 28, 2017 15:59
-
-
Save tdiprima/16862174ecea5407a7c6eee7c2812e7c to your computer and use it in GitHub Desktop.
Spin up a docker container
This file contains hidden or 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
#!/bin/bash | |
if [ $# -eq 0 ] | |
then | |
# change to whatever default you like | |
IMAGE_NAME="YOUR-DOCKER-IMAGE" | |
CONTAINER_NAME="YOUR-DOCKER-CONTAINER" | |
REPO_NAME="YOUR-GITHUB-REPOSITORY" # NOTE: Name only; not the URL. | |
else | |
IMAGE_NAME="$1" | |
CONTAINER_NAME="$2" | |
REPO_NAME="$3" | |
fi | |
kill_it() | |
{ | |
# Stop container and remove | |
name="$CONTAINER_NAME" | |
docker stop "$name" | |
docker rm "$name" | |
# Remove image | |
docker rmi "$IMAGE_NAME" | |
} | |
clone() | |
{ | |
# Clone new repo (or refactor to `git pull`, whichever you prefer) | |
rm -rf "$REPO_NAME" | |
git clone -b release "https://github.com/camicroscope/$REPO_NAME.git" # NOTE: Cloning branch | |
} | |
build() | |
{ | |
# Build new image | |
docker build -t "$IMAGE_NAME" "$REPO_NAME" | |
} | |
run() | |
{ | |
# Run the container | |
# NOTE: Network name... | |
viewer_container=$(docker run --name="$CONTAINER_NAME" --net=quip_nw --restart unless-stopped -itd \ | |
-p $VIEWER_PORT:80 \ | |
-v "$IMAGES_DIR":/data/images \ | |
-v "$STORAGE_FOLDER"/configs/security:/var/www/html/config \ | |
"$IMAGE_NAME") | |
echo "$viewer_container" | |
echo "It's started..." | |
} | |
# NOTE: "$HOME/github" is location of repo | |
cd "$HOME/github" || (echo "Could not cd. Exiting..." && exit 1) | |
STORAGE_FOLDER="$HOME/install_folder" # NOTE: this is already set up | |
IMAGES_DIR="$STORAGE_FOLDER/img" | |
VIEWER_PORT=80 | |
# Run the commands | |
kill_it | |
clone | |
build | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script: