From 26dcece49100f626a4646c6525aea78ef115518b Mon Sep 17 00:00:00 2001 From: "jose.lausuch" Date: Sat, 26 Dec 2015 21:55:45 +0100 Subject: Wait for containers to be removed before removing images This will avoid some errors like this: "Error response from daemon: conflict: unable to delete 44c2887519de (must be forced) - image is being used by stopped container 7dbed6d40e5a" Change-Id: I54b8b76fbcc6f208ab52c88b43ea18af935e69c7 Signed-off-by: jose.lausuch --- jjb/opnfv/opnfv-docker.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'jjb') diff --git a/jjb/opnfv/opnfv-docker.sh b/jjb/opnfv/opnfv-docker.sh index 6f0a0c35c..d65603fec 100644 --- a/jjb/opnfv/opnfv-docker.sh +++ b/jjb/opnfv/opnfv-docker.sh @@ -12,8 +12,18 @@ echo # Remove previous running containers if exist if [[ ! -z $(docker ps -a | grep $DOCKER_REPO_NAME) ]]; then echo "Removing existing $DOCKER_REPO_NAME containers..." - docker ps | grep $DOCKER_REPO_NAME | awk '{{print $1}}' | xargs docker stop - docker ps -a | grep $DOCKER_REPO_NAME | awk '{{print $1}}' | xargs docker rm + #docker ps | grep $DOCKER_REPO_NAME | awk '{{print $1}}' | xargs docker stop + docker ps -a | grep $DOCKER_REPO_NAME | awk '{{print $1}}' | xargs docker rm -f + t=60 + # Wait max 60 sec for containers to be removed + while [ $t -gt 0 ]; do + ids=$(docker ps | grep $DOCKER_REPO_NAME |awk '{{print $1}}') + if [[ -z $ids ]]; then + break + fi + sleep 1 + let t=t-1 + done fi @@ -24,7 +34,7 @@ if [[ ! -z $(docker images | grep $DOCKER_REPO_NAME) ]]; then image_tags=($(docker images | grep $DOCKER_REPO_NAME | awk '{{print $2}}')) for tag in "${{image_tags[@]}}"; do echo "Removing docker image $DOCKER_REPO_NAME:$tag..." - docker rmi $DOCKER_REPO_NAME:$tag + docker rmi -f $DOCKER_REPO_NAME:$tag done fi @@ -36,7 +46,7 @@ if [[ "$UPDATE_LATEST_STABLE" == "true" ]]; then echo "ERROR: The image $DOCKER_REPO_NAME with tag $STABLE_TAG does not exist." exit 1 fi - docker tag $DOCKER_REPO_NAME:$STABLE_TAG $DOCKER_REPO_NAME:latest_stable + docker tag -f $DOCKER_REPO_NAME:$STABLE_TAG $DOCKER_REPO_NAME:latest_stable echo "Pushing $DOCKER_REPO_NAME:latest_stable ..." docker push $DOCKER_REPO_NAME:latest_stable exit 0 -- cgit 1.2.3-korg