diff --git a/README.md b/README.md index 0084c4a..141f82f 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,9 @@ Runs command as root, instead of current user. ### --rm Removes the specified container. +### --rmi +Removes image generated by the `otherworld` script (`image_$CONTAINER_NAME`) + ### --commit Commits the container to an image named `image_$CONTAINER_NAME`. diff --git a/otherworld b/otherworld index 2444c69..ab0d0c1 100755 --- a/otherworld +++ b/otherworld @@ -72,6 +72,9 @@ def docker_commit (container, image_name): def docker_rm (container): call(["docker", "rm", "-f", container]) +def docker_rmi (container): + call(["docker", "rmi", "-f", container]) + def docker_build (build_path, options, image_name): check_call(["docker", "build"] + options + ["-t", image_name, build_path]) return image_name @@ -132,6 +135,9 @@ while len(command) > 0: elif arg == "--rm": actions.append("rm") command = command[1:] + elif arg == "--rmi": + actions.append("rmi") + command = command[1:] elif arg == "--commit": actions.append("commit") command = command[1:] @@ -173,6 +179,12 @@ if actions: print(f">> Removing container: {container_name}") docker_rm(container_name) + if "rmi" in actions: + target_image_name = get_generated_image_name(container_name) + if not quiet: + print(f">> Removing image: {target_image_name}") + docker_rmi(target_image_name) + if not command: sys.exit(0)