Skip to content

Commit

Permalink
Remove named volumes during "down -v"
Browse files Browse the repository at this point in the history
Fixes containers#105

Signed-off-by: Luiz Carvalho <[email protected]>
  • Loading branch information
lcarva authored and muayyad-alsadi committed Nov 23, 2021
1 parent 1555417 commit e879529
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,13 @@ def run(self, podman_args, cmd='', cmd_args=None, wait=True, sleep=1, obj=None):
time.sleep(sleep)
return p

def volume_inspect_all(self):
output = self.output(["volume", "inspect", "--all"]).decode('utf-8')
return json.loads(output)

def volume_rm(self, name):
return self.run(["volume", "rm", name])

def normalize_service(service):
for key in ("env_file", "security_opt"):
if key not in service: continue
Expand Down Expand Up @@ -1493,6 +1500,12 @@ def compose_down(compose, args):
return
for pod in compose.pods:
compose.podman.run([], "pod", ["rm", pod["name"]], sleep=0)
if args.volumes:
volumes = compose.podman.volume_inspect_all()
for volume in volumes:
project = volume.get("Labels", {}).get("io.podman.compose.project")
if project == compose.project_name:
compose.podman.volume_rm(volume["Name"])

@cmd_run(podman_compose, 'ps', 'show status of containers')
def compose_ps(compose, args):
Expand Down Expand Up @@ -1652,6 +1665,12 @@ def compose_up_parse(parser):
parser.add_argument("--exit-code-from", metavar='SERVICE', type=str, default=None,
help="Return the exit code of the selected service container. Implies --abort-on-container-exit.")

@cmd_parse(podman_compose, 'down')
def compose_down_parse(parser):
parser.add_argument("-v", "--volumes", action='store_true', default=False,
help="Remove named volumes declared in the `volumes` section of the Compose file and "
"anonymous volumes attached to containers.")

@cmd_parse(podman_compose, 'run')
def compose_run_parse(parser):
parser.add_argument("-d", "--detach", action='store_true',
Expand Down

0 comments on commit e879529

Please sign in to comment.