Skip to content

Instantly share code, notes, and snippets.

@oozman
Last active May 21, 2020 00:23
Show Gist options
  • Save oozman/1e83ad2fc8b7d99f2f1a0d250ac1fa6c to your computer and use it in GitHub Desktop.
Save oozman/1e83ad2fc8b7d99f2f1a0d250ac1fa6c to your computer and use it in GitHub Desktop.

Revisions

  1. oozman revised this gist May 21, 2020. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions restart.bash
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,9 @@
    #!/bin/bash

    # Usage: ./restart.bash <container-name>
    # Usage: ./restart.bash <container-name> <domain name>

    CONTAINER_NAME=$1
    CONTAINER_DOMAIN=$2

    # Build
    docker build -t $CONTAINER_NAME .
    @@ -26,6 +27,6 @@ then
    fi

    # Run the container again.
    docker run -d -p 8000:80 --name $CONTAINER_NAME $CONTAINER_NAME
    docker run -d -e VIRTUAL_HOST=$CONTAINER_DOMAIN --restart always --name $CONTAINER_NAME $CONTAINER_NAME

    echo "Container has been restarted."
  2. oozman revised this gist May 7, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions restart.bash
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    #!/bin/bash

    # Usage: ./restart.bash <container-name>

    CONTAINER_NAME=$1

    # Build
  3. oozman created this gist May 7, 2020.
    29 changes: 29 additions & 0 deletions restart.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/bin/bash

    CONTAINER_NAME=$1

    # 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 -p 8000:80 --name $CONTAINER_NAME $CONTAINER_NAME

    echo "Container has been restarted."