diff --git a/run/scripts/update b/run/scripts/update index 1d5d3213cdbd393f90565055b8d3dd29bde3ec40..179d180174e91bc740a8ee388e015d7b6968f49f 100755 --- a/run/scripts/update +++ b/run/scripts/update @@ -1,19 +1,28 @@ #!/bin/bash if [[ -n ${PHP_VERSION} ]]; then - IMAGEID=$(docker image ls -q registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${VERSION}) echo "Updating the image ..." STATUS=$(docker pull registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${VERSION}) if [[ "$STATUS" == *"Status: Image is up to date"* ]]; then echo "Already up to date" else echo "Image updated" + NEWIMAGEID=$(docker image ls -q registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${VERSION} | head -1) while true; do - ID=$(docker container ls -q -f ancestor=${IMAGEID}) - if [[ -n ${ID} ]]; then - echo "Removing outdated container ..." - docker stop ${ID} - docker rm ${ID} + IMAGEID=$(docker image ls -q registry.lakedrops.com/docker/l3d/php-${PHP_VERSION} | grep --invert-match ${NEWIMAGEID}) + if [[ -n ${IMAGEID} ]]; then + while true; do + ID=$(docker container ls -q -f ancestor=${IMAGEID}) + if [[ -n ${ID} ]]; then + echo "Removing outdated container ..." + docker stop ${ID} + docker rm ${ID} + else + break + fi + done + echo "Removing outdated image ..." + docker rmi ${IMAGEID} else break fi