Last active
January 11, 2016 17:12
-
-
Save ironicbadger/f5d56d0f86c9cde334c2 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Replaces a container with an upgraded version from Docker Hub and recreates | |
# using arguments supplied via /opt/docker.list | |
CONTAINER_NAME="$@" | |
LIST="docker.list" | |
# check docker.list exists, exit if not | |
{ | |
if [ ! -f $LIST ]; then | |
echo "docker.list not found!" | |
exit 0 | |
fi | |
} | |
# check specified container exists in docker.list, exit if not | |
# read from docker.list the specified containers 'create' command | |
DOCKER_CREATE=$(sed -n "/^docker create --name $CONTAINER_NAME \\\\$/,/\/$CONTAINER_NAME$/p" $LIST | sed -E 's/(".*")|\\/\1/g') | |
echo $DOCKER_CREATE | |
# check if container already exists (docker ps -a), stop + remove if yes | |
{ | |
if docker ps | grep $CONTAINER_NAME; | |
then | |
echo "Container exists already..." | |
docker pull ${DOCKER_CREATE##* } | |
docker stop $CONTAINER_NAME | |
docker rm $CONTAINER_NAME | |
$DOCKER_CREATE | |
docker start $CONTAINER_NAME | |
else | |
echo "Container doesn't exist, exiting..." | |
exit 0 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment