Created
October 12, 2016 09:56
-
-
Save Sh4kE/6fb262015a2a08f9cc445c3f2f81621b to your computer and use it in GitHub Desktop.
Bash script to update docker containers to a new image
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
#!/usr/bin/env bash | |
set -e | |
REGISTRY="wischlabs" | |
BASE_IMAGE="ofm_helper" | |
IMAGE="$REGISTRY/$BASE_IMAGE" | |
CID=$(docker ps | grep $BASE_IMAGE | awk '{print $1}') | |
docker pull $IMAGE | |
for im in $CID | |
do | |
LATEST=`docker inspect --format "{{.Id}}" $IMAGE` | |
RUNNING=`docker inspect --format "{{.Image}}" $im` | |
NAME=`docker inspect --format '{{.Name}}' $im | sed "s/\///g"` | |
echo "Latest:" $LATEST | |
echo "Running:" $RUNNING | |
if [ "$RUNNING" != "$LATEST" ];then | |
echo "upgrading $NAME" | |
docker stop $NAME | |
docker rm -f $NAME | |
docker run -d --name $BASE_IMAGE --restart=unless-stopped $IMAGE | |
else | |
echo "$NAME up to date" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment