Skip to content
Snippets Groups Projects
Commit a22188c0 authored by jurgenhaas's avatar jurgenhaas
Browse files

#9 Remove all outdated containers when an image got updated

parent 817bb1e5
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,7 @@ fi ...@@ -48,6 +48,7 @@ fi
ID=$(docker container ls -q -f name=${COMPOSE_PROJECT_NAME}_l3d) ID=$(docker container ls -q -f name=${COMPOSE_PROJECT_NAME}_l3d)
if [[ "$1" == "update" ]]; then if [[ "$1" == "update" ]]; then
IMAGEID=$(docker image ls -q registry.lakedrops.com/docker/l3d:php-${PHP_VERSION})
echo "Updating the image ..." echo "Updating the image ..."
STATUS=$(docker pull registry.lakedrops.com/docker/l3d:php-${PHP_VERSION}) STATUS=$(docker pull registry.lakedrops.com/docker/l3d:php-${PHP_VERSION})
if [[ "$STATUS" == *"Status: Image is up to date"* ]]; then if [[ "$STATUS" == *"Status: Image is up to date"* ]]; then
...@@ -55,10 +56,16 @@ if [[ "$1" == "update" ]]; then ...@@ -55,10 +56,16 @@ if [[ "$1" == "update" ]]; then
else else
echo "Image updated" echo "Image updated"
if [[ -n "$ID" ]]; then if [[ -n "$ID" ]]; then
echo "Removing outdated container ..." while true; do
docker stop ${COMPOSE_PROJECT_NAME}_l3d ID=$(docker container ls -q -f ancestor=${IMAGEID})
docker rm ${COMPOSE_PROJECT_NAME}_l3d if [[ -n "$ID" ]]; then
ID= echo "Removing outdated container ..."
docker stop ${ID}
docker rm ${ID}
else
break
fi
done
fi fi
fi fi
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment