Created
January 11, 2016 17:09
-
-
Save ironicbadger/b59817d9558b1fb5a6d1 to your computer and use it in GitHub Desktop.
dcreate
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 | |
CREATE=$(sed -n "/^docker create --name $CONTAINER_NAME \\\\$/,/\/$CONTAINER_NAME$/p" $LIST | sed -E 's/(".*")|\\/\1/g') | |
echo $CREATE | |
# check if container already exists (docker ps -a), stop + remove if yes | |
{ | |
if docker ps | grep $CONTAINER_NAME; | |
then | |
echo "Container exists already, no need to create. Exiting..." | |
exit 0 | |
else | |
echo "Container doesn't exist, creating..." | |
eval $CREATE | |
docker start $CONTAINER_NAME | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment