Skip to content

Instantly share code, notes, and snippets.

@Sh4kE
Created October 12, 2016 09:56
Show Gist options
  • Save Sh4kE/6fb262015a2a08f9cc445c3f2f81621b to your computer and use it in GitHub Desktop.
Save Sh4kE/6fb262015a2a08f9cc445c3f2f81621b to your computer and use it in GitHub Desktop.
Bash script to update docker containers to a new image
#!/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