Created
April 28, 2016 11:24
-
-
Save vermotr/f9ba7dc5cd7834b9c9730e4e1a5e9cab to your computer and use it in GitHub Desktop.
Bash script to upgrade docker container after its image changed
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 | |
if [ $# -lt 1 ];then | |
echo Usage: `basename $0` image 1>&2 | |
exit 1 | |
fi | |
set -e | |
IMAGE=$1 | |
CID=$(docker ps | grep $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 [ "$LATEST" != "$RUNNING" ];then | |
echo "upgrading $NAME" | |
docker stop $NAME | |
docker rm -f $NAME | |
# here, create your image | |
docker start $NAME | |
else | |
echo "$NAME up to date" | |
fi | |
done |
Error: failed to start containers :(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! I may well be using this soon.