From 531befbaf4d758933488fa30bda65ea5e6313ab5 Mon Sep 17 00:00:00 2001 From: Christian Klopp Date: Tue, 12 Jun 2018 14:29:42 +0200 Subject: [PATCH] enhances cleanup for building docker containers in error cases --- create-binary-docker | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/create-binary-docker b/create-binary-docker index 56f20cc..ea9b212 100755 --- a/create-binary-docker +++ b/create-binary-docker @@ -260,6 +260,14 @@ rm -f "${target_docker_binary}" rm -f "${docker_tmp}/${name}-dependencies.txt" ${docker_cmd} rm -f ${build_container_name} &> /dev/null printf "done\n" + +# remove dangling images +separator_line +printf "### Removing dangled images..." +for image in $(${docker_cmd} images -qa -f "dangling=true"); do + ${docker_cmd} rmi -f ${image} > /dev/null +done +printf "done\n" } trap cleanup SIGINT SIGTERM @@ -391,7 +399,7 @@ printf "%s\n" $(get_requirements_from_setup_file) | tr " " "\n" > \ separator_line printf "### Building %s-%s container...\n" ${name} ${machine} -${docker_cmd} build -t ${target_docker_name} \ +${docker_cmd} build --force-rm -t ${target_docker_name} \ -f ${target_docker_file} ${docker_path} if [ $? -gt 0 ]; then printf "### Building %s-%s container failed. Exiting now.\n" \ @@ -405,15 +413,6 @@ printf "### Base %s-%s container built successfully.\n" ${name} ${machine} # cleanup cleanup -############################################################################## -# remove dangling images -separator_line -printf "### Removing dangled images..." -for image in $(${docker_cmd} images -qa -f "dangling=true"); do - ${docker_cmd} rmi -f ${image} > /dev/null -done -printf "done\n" - ############################################################################## # example to run the docker file #${docker_cmd} run --name test -d \