Skip to content

Instantly share code, notes, and snippets.

@tdiprima
Last active June 28, 2017 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdiprima/16862174ecea5407a7c6eee7c2812e7c to your computer and use it in GitHub Desktop.
Save tdiprima/16862174ecea5407a7c6eee7c2812e7c to your computer and use it in GitHub Desktop.
Spin up a docker container
#!/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
@tdiprima
Copy link
Author

tdiprima commented Jun 28, 2017

Script:

  • Stop and remove container
  • Remove image
  • Remove local GitHub repo
  • Clone GitHub repo
  • Build image (from repo)
  • Start image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment