Skip to content

Instantly share code, notes, and snippets.

@ppalms
Created April 24, 2019 22:08
Show Gist options
  • Save ppalms/76c777c7c10cda42acbd30087fe3b322 to your computer and use it in GitHub Desktop.
Save ppalms/76c777c7c10cda42acbd30087fe3b322 to your computer and use it in GitHub Desktop.
DigitalOcean docker deploy script
#!/bin/bash
###########################################################################
# Put this on a DigitalOcean droplet (or wherever you're deploying) and
# run chmod +x deploy_app.sh to make the script executable
#
# Execute this script: ./deploy_app.sh jittles/dockerhub-repo-name:$TAG
# Replace dockerhub-repo-name with the name of the Docker Hub repository
# you want to deploy
# Replace $TAG with the actual Build Tag you want to deploy
#
###########################################################################
set -e
DOCKER_IMAGE=$1
CONAINER_NAME="dockerhub-repo-name"
# Check for arguments
if [[ $# -lt 1 ]] ; then
echo "[ERROR] You must supply a Docker Hub Image to pull"
exit 1
fi
echo "Deploying to Docker Container"
# Check for running container and stop it before starting a new one (stopping will also purge the old image)
if [ $(docker inspect -f '{{.State.Running}}' $CONAINER_NAME) = "true" ]; then
docker stop dockerhub-repo-name
fi
echo "Starting Docker Image name: $DOCKER_IMAGE"
docker run -d --rm=true \
-e SQLCONNSTR_DefaultConnection='' \
-e SHARED_KEY='' \
-p 80:8080 \
--name dockerhub-repo-name $DOCKER_IMAGE
docker ps -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment