问题原文
原帖链接 · Ranunculum · CC BY-SA 3.0
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
社区高分解答
原帖链接 · ElectRocnic · CC BY-SA 4.0
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
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
