Skip to content
New issue

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

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

Already on GitHub? # to your account

fix docker container rm -v flag description and docs to mention "anonymous" volumes only #2285

Closed
thaJeztah opened this issue Jan 24, 2020 · 4 comments · Fixed by #2289
Closed

Comments

@thaJeztah
Copy link
Member

Need to double-check if this was by design, but docker rm -v (remove container including volumes attached to it) only removes anonymous volumes, but not named ones. However, the flag description does not mention this;

docker container rm --help

Usage:	docker rm [OPTIONS] CONTAINER [CONTAINER...]

Remove one or more containers

Options:
  -f, --force     Force the removal of a running container (uses SIGKILL)
  -l, --link      Remove the specified link
  -v, --volumes   Remove the volumes associated with the container

Steps to verify the current behavior:

docker run -d --name mycontainer1 -v /anonymous -v namedvol1:/namedvol nginx:alpine
docker run -d --name mycontainer2 -v /anonymous -v namedvol2:/namedvol nginx:alpine

docker volume ls

DRIVER              VOLUME NAME
local               547d032c5571241ec33b6064dcaef1116c646b8a7e590a18bc56da9a2a22ddab
local               402827d64bced57d80125e52606d6b394c651c138cb829587798b041357523c2
local               namedvol1
local               namedvol2

Removing mycontainer1 keeps all volumes associated with the container:

docker rm -f mycontainer1
docker volume ls
DRIVER              VOLUME NAME
local               547d032c5571241ec33b6064dcaef1116c646b8a7e590a18bc56da9a2a22ddab
local               402827d64bced57d80125e52606d6b394c651c138cb829587798b041357523c2
local               namedvol1
local               namedvol2

Whereas using the -v option removes the anonymous volume, but keeps the named volume:

docker rm -fv mycontainer2
docker volume ls
DRIVER              VOLUME NAME
local               547d032c5571241ec33b6064dcaef1116c646b8a7e590a18bc56da9a2a22ddab
local               namedvol1
local               namedvol2
@thaJeztah
Copy link
Member Author

Note that docker run --rm (run and auto-remove after exiting) does always remove anonymous volumes

@thaJeztah
Copy link
Member Author

/cc @ndeloof @cpuguy83

@cpuguy83
Copy link
Collaborator

@thaJeztah
Copy link
Member Author

Thanks! I thought it was, but know there has been some back-and-forth around this 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants