Make containers persistent, recreate them only when needed
This commit is contained in:
parent
13275017f6
commit
218859a7ea
|
@ -26,6 +26,9 @@ trap finish EXIT
|
||||||
volume_prefix=cloner
|
volume_prefix=cloner
|
||||||
clone_prefix=cloner-runner
|
clone_prefix=cloner-runner
|
||||||
|
|
||||||
|
# last version of image
|
||||||
|
last_version=$(docker images $mirror_image --no-trunc --quiet)
|
||||||
|
|
||||||
name=${1:-}
|
name=${1:-}
|
||||||
[ -n "$name" ] || die "No volume specified"
|
[ -n "$name" ] || die "No volume specified"
|
||||||
|
|
||||||
|
@ -47,21 +50,28 @@ then
|
||||||
fi
|
fi
|
||||||
unset lines
|
unset lines
|
||||||
|
|
||||||
# does it exist?
|
# check if volume does exist?
|
||||||
docker ps --quiet -a --no-trunc --filter name=^/$container_name$ > $scratch/existing
|
|
||||||
lines=$(wc -l $scratch/existing | cut -d' ' -f1)
|
|
||||||
|
|
||||||
if ! [ $lines -eq 0 ]
|
|
||||||
then
|
|
||||||
log "Conflicting container exists, removing.."
|
|
||||||
docker rm $(cat $scratch/existing)
|
|
||||||
fi
|
|
||||||
|
|
||||||
unset lines
|
|
||||||
|
|
||||||
# does volume exist?
|
|
||||||
docker volume inspect $name > /dev/null 2>&1 || die "Volume '$name' does not exist - exiting!"
|
docker volume inspect $name > /dev/null 2>&1 || die "Volume '$name' does not exist - exiting!"
|
||||||
|
|
||||||
|
# does it exist?
|
||||||
|
image_version=$(docker inspect --format='{{.Image}}' $container_name 2>/dev/null || true)
|
||||||
|
|
||||||
|
# do I need to recreate image?
|
||||||
|
if ! [ "x$image_version" = "x$last_version" ]
|
||||||
|
then
|
||||||
|
# not empty string - need to delete first
|
||||||
|
if [ -n "$image_version" ]
|
||||||
|
then
|
||||||
|
log "Conflicting container exists, removing.."
|
||||||
|
docker rm $container_name
|
||||||
|
fi
|
||||||
|
# create new container
|
||||||
|
log "Creating new version of container.."
|
||||||
|
docker create -v $name:/data --name $container_name $mirror_image
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
log "Running container of update process..."
|
log "Running container of update process..."
|
||||||
docker run -v $name:/data --name $container_name --rm $mirror_image | while read line; do log "$line"; done
|
docker start -a $container_name | while read line; do log "$line"; done
|
||||||
log "Finished."
|
log "Finished."
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user