Last active
May 21, 2020 00:23
-
-
Save oozman/1e83ad2fc8b7d99f2f1a0d250ac1fa6c to your computer and use it in GitHub Desktop.
Simple script to re-deploy a container via SSH.
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 | |
# Usage: ./restart.bash <container-name> <domain name> | |
CONTAINER_NAME=$1 | |
CONTAINER_DOMAIN=$2 | |
# Build | |
docker build -t $CONTAINER_NAME . | |
# Check if container is running. | |
CONTAINER_IDS=$(docker ps -aq --filter name=$CONTAINER_NAME) | |
IS_CONTAINER_RUNNING=0 | |
if [ -z "$CONTAINER_IDS" ] | |
then | |
IS_CONTAINER_RUNNING=0 | |
else | |
IS_CONTAINER_RUNNING=1 | |
fi | |
# Stop and delete container, if it's running | |
if [[ $IS_CONTAINER_RUNNING -eq 1 ]] | |
then | |
docker stop $CONTAINER_IDS | |
docker rm $CONTAINER_IDS | |
echo "Container has been stopped." | |
fi | |
# Run the container again. | |
docker run -d -e VIRTUAL_HOST=$CONTAINER_DOMAIN --restart always --name $CONTAINER_NAME $CONTAINER_NAME | |
echo "Container has been restarted." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment