Add --rmi command that removes the generated image.

This commit is contained in:
Adrian Kuschelyagi Malacoda 2020-08-20 02:49:34 -05:00
parent 71fe46e881
commit b1878aef1b
2 changed files with 15 additions and 0 deletions

View File

@ -29,6 +29,9 @@ Runs command as root, instead of current user.
### --rm ### --rm
Removes the specified container. Removes the specified container.
### --rmi
Removes image generated by the `otherworld` script (`image_$CONTAINER_NAME`)
### --commit ### --commit
Commits the container to an image named `image_$CONTAINER_NAME`. Commits the container to an image named `image_$CONTAINER_NAME`.

View File

@ -72,6 +72,9 @@ def docker_commit (container, image_name):
def docker_rm (container): def docker_rm (container):
call(["docker", "rm", "-f", container]) call(["docker", "rm", "-f", container])
def docker_rmi (container):
call(["docker", "rmi", "-f", container])
def docker_build (build_path, options, image_name): def docker_build (build_path, options, image_name):
check_call(["docker", "build"] + options + ["-t", image_name, build_path]) check_call(["docker", "build"] + options + ["-t", image_name, build_path])
return image_name return image_name
@ -132,6 +135,9 @@ while len(command) > 0:
elif arg == "--rm": elif arg == "--rm":
actions.append("rm") actions.append("rm")
command = command[1:] command = command[1:]
elif arg == "--rmi":
actions.append("rmi")
command = command[1:]
elif arg == "--commit": elif arg == "--commit":
actions.append("commit") actions.append("commit")
command = command[1:] command = command[1:]
@ -173,6 +179,12 @@ if actions:
print(f">> Removing container: {container_name}") print(f">> Removing container: {container_name}")
docker_rm(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: if not command:
sys.exit(0) sys.exit(0)