docker volume rm --force has no impact
According to the official documentation it is possible to "force" remove a volume. The documentation remains quite unspecific what is meant by --force
. To what I have found so far in the web this implicates the removal of volumes that are still in use by other containers.
Using the --force
option appears to have no impact:
$ docker volume create mydata
$ docker docker run -v mydata:/mydata alpine:latest /bin/sh -c "touch /mydata/mydata.test; ls /mydata"
$ docker volume rm --force mydata
Error response from daemon: unable to remove volume: remove mydata: volume is in use - [1cbcfa3d47a32db7b0075e113216f7146a436a4da22a97dc2f7b60c68de95c3d]
This is the same output as when omitting the --force
flag. Is this a bug or am I misunderstanding something?
$ docker version
Client:
Version: 18.01.0-ce
API version: 1.35
Go version: go1.9.2
Git commit: 03596f5
Built: Wed Jan 10 20:09:13 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.01.0-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.2
Git commit: 03596f5
Built: Wed Jan 10 20:07:43 2018
OS/Arch: linux/amd64
Experimental: false
Solution 1:
I am annoyed by all answers on all posts which do NOT provide a solution for the case which is mentioned by OP: The --force flag DOES NOT HELP.
Workaround (ATTENTION, you really should know what you do!):
docker volume ls # To list the volumes which currently exist
# To get the absolute path to the directory on your system where docker
# actually stores this volume
docker volume inspect --format '{{ .Mountpoint }}' <volume-name>
# E.g. sudo rm -rf /var/lib/docker/volumes/database_volume (without the
# _data directory)
sudo rm -rf <path-from-above>
# Needed so docker will reload its volumes-directory to no longer list the
# deleted volume under docker volume ls and no longer make headaches on any
# build- or run-attempts.
sudo service docker restart
Solution 2:
use the --filter flag to see which containers are using the volume:
docker ps --filter volume=mydata
then, stop the container that is using that volume.
Finally, remove the volume if you wish to do so:
docker volume rm --force mydata