Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove named volumes during "down -v" #214

Merged
merged 1 commit into from
Nov 23, 2021

Conversation

lcarva
Copy link
Contributor

@lcarva lcarva commented Jul 10, 2020

Fixes #105

Signed-off-by: Luiz Carvalho [email protected]

@lcarva
Copy link
Contributor Author

lcarva commented Oct 13, 2020

@muayyad-alsadi any chance you could have a look on this one? Thanks in advance!

@muayyad-alsadi
Copy link
Collaborator

I'm very sorry for taking so long. I've moved to a new house and I feel I must review this one because I don't want to remove volumes by mistake.

BTW we can remove volumes using labels.

@lcarva
Copy link
Contributor Author

lcarva commented Oct 13, 2020

I'm very sorry for taking so long. I've moved to a new house and I feel I must review this one because I don't want to remove volumes by mistake.

BTW we can remove volumes using labels.

No worries! I hope the new house is wonderful.

I've tried to use a single podman command to remove all the volumes based on labels, but was not able to do so. I've opted to listing all the volumes and inspecting the labels on each one. I'm happy to hear an alternative approach.

I also tried using podman volume ls which has a filter option. However, this seems to only allow filtering by label name, and not its value.

@muayyad-alsadi
Copy link
Collaborator

No worries! I hope the new house is wonderful.

in deed, it's a nice villa.

I've tried to use a single podman command to remove all the volumes based on labels,

we set a label io.podman.compose.project with value equal to project name
the single command is

podman volume list --format '{{.Name}}' -f 'label=io.podman.compose.project=HERE' | xargs -r podman volume rm

I had the following todo comment in the source code

    # TODO: might move to using "volume list"
    # podman volume list --format '{{.Name}}\t{{.MountPoint}}' -f 'label=io.podman.compose.project=HERE'
    try: out = compose.podman.output(["volume", "inspect", vol_name]).decode('utf-8')
    except subprocess.CalledProcessError:
        compose.podman.output(["volume", "create", "--label", "io.podman.compose.project={}".format(proj_name), vol_name])
        out = compose.podman.output(["volume", "inspect", vol_name]).decode('utf-8')

@lcarva
Copy link
Contributor Author

lcarva commented Oct 14, 2020

No worries! I hope the new house is wonderful.

in deed, it's a nice villa.

I've tried to use a single podman command to remove all the volumes based on labels,

we set a label io.podman.compose.project with value equal to project name
the single command is

podman volume list --format '{{.Name}}' -f 'label=io.podman.compose.project=HERE' | xargs -r podman volume rm

I had the following todo comment in the source code

    # TODO: might move to using "volume list"
    # podman volume list --format '{{.Name}}\t{{.MountPoint}}' -f 'label=io.podman.compose.project=HERE'
    try: out = compose.podman.output(["volume", "inspect", vol_name]).decode('utf-8')
    except subprocess.CalledProcessError:
        compose.podman.output(["volume", "create", "--label", "io.podman.compose.project={}".format(proj_name), vol_name])
        out = compose.podman.output(["volume", "inspect", vol_name]).decode('utf-8')

Yes, I saw that. That syntax doesn't work for me with podman 2.1.1.

@markandrewj
Copy link

Any word on this? I notice the discussion around it stopped in 2020.

@sferich888
Copy link

@lcarva can we fix the merge conflicts?

@lcarva
Copy link
Contributor Author

lcarva commented Nov 22, 2021

@lcarva can we fix the merge conflicts?

Done!

@muayyad-alsadi muayyad-alsadi merged commit e879529 into containers:devel Nov 23, 2021
@muayyad-alsadi
Copy link
Collaborator

I'll invite you to jump to 1.x branch and start playing with it. I'll port this fix to it.

0.1 for legacy versions of podman, 1.x for modern versions (CNI network, no need for mapping and workarounds).

by the end of this weekend I hope I can update the documentation.

@muayyad-alsadi
Copy link
Collaborator

@lcarva why you used

podman volume inspect --all

instead of

podman volume ls --noheading -f label=io.podman.compose.project=simple --format '{{.Name}}'

what are the podman versions that don't support the latter?

@lcarva
Copy link
Contributor Author

lcarva commented Jan 6, 2022

@lcarva why you used

podman volume inspect --all

instead of

podman volume ls --noheading -f label=io.podman.compose.project=simple --format '{{.Name}}'

what are the podman versions that don't support the latter?

Podman 2.1.1 is what I had used, but that was over a year ago.

The -f filtering was just not working at all. IIRC, it was not checking the value of the label, just its name. It would return any volume that had the label io.podman.compose.project regardless of its value.

I just tried this again with Podman 3.4.4 and it appears to have been fixed. containers/podman#8345 appears to be the fix.

+1 to switching to using that now, but it may not work for older versions of podman.

@lcarva
Copy link
Contributor Author

lcarva commented Jan 6, 2022

+1 to switching to using that now, but it may not work for older versions of podman.

PR submitted: #402

@muayyad-alsadi
Copy link
Collaborator

podman-compose version 1.x is for podman>=3.1.0
we are safe to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove all volumes when shutting down
4 participants