EDIT (2/19/21): A lot of time has elapsed since I asked this original question years ago and I've seen a flurry of activity since then. I re-selected an answer which I think is consistent with the most localized and safe option for solving this issue (which is typically associated with docker-compose). While docker did introduce the prune command, it is generally a dangerous operation and I would be cautious about using it as you may unintentionally impact other applications or setups you have on your machine
我在使用Docker 1.9.1删除Docker卷时遇到了一些问题。
我已经删除了所有停止的容器,因此docker ps -a返回空。
当我使用docker卷ls时,我得到了一大堆docker容器:
docker volume ls
DRIVER VOLUME NAME
local a94211ea91d66142886d72ec476ece477bb5d2e7e52a5d73b2f2f98f6efa6e66
local 4f673316d690ca2d41abbdc9bf980c7a3f8d67242d76562bbd44079f5f438317
local eb6ab93effc4b90a2162e6fab6eeeb65bd0e4bd8a9290e1bad503d2a47aa8a78
local 91acb0f7644aec16d23a70f63f70027899017a884dab1f33ac8c4cf0dabe5f2c
local 4932e2fbad8f7e6246af96208d45a266eae11329f1adf176955f80ca2e874f69
local 68fd38fc78a8f02364a94934e9dd3b5d10e51de5b2546e7497eb21d6a1e7b750
local 7043a9642614dd6e9ca013cdf662451d2b3df6b1dddff97211a65ccf9f4c6d47
#etc x 50
由于这些卷都不包含任何重要的内容,我尝试使用docker卷rm $(docker卷ls -q)清除所有卷。
在这个过程中,大部分都被删除了,但我得到了:
Error response from daemon: Conflict: volume is in use
Error response from daemon: Conflict: volume is in use
Error response from daemon: Conflict: volume is in use
Error response from daemon: Conflict: volume is in use
Error response from daemon: Conflict: volume is in use
他们中的很大一部分人。如果我一开始就没有任何容器存在,那么如何使用这些卷呢?
我对Docker还是个新手。我正在清理一些初始测试混乱,也无法删除一个卷。我已经停止了所有正在运行的实例,执行了一个docker rmi -f $(docker image ls -q),但仍然收到了来自daemon: unable to remove volume: remove uuid: volume is in use的错误响应。
我做了一个docker系统修剪,它清理了需要删除的最后一个卷:
[0]$ docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
... about 15 containers UUID's truncated
Total reclaimed space: 2.273MB
[0]$ docker volume ls
DRIVER VOLUME NAME
local uuid
[0]$ docker volume rm uuid
uuid
[0]$
Docker系统修剪
要使用此命令,客户机和守护进程API都必须至少为1.25。使用
在客户端上使用docker version命令检查客户端和守护进程的API版本。
只要卷与容器相关联(运行或未运行),就不能删除卷。
你必须要跑
docker inspect <container-id>/<container-name>
在每个运行/非运行的容器上,此卷可能已被挂载到其中。
如果卷被挂载到任何一个容器上,您应该在inspect命令输出的Mounts部分中看到它。大概是这样的:-
"Mounts": [
{
"Type": "volume",
"Name": "user1",
"Source": "/var/lib/docker/volumes/user1/_data",
"Destination": "/opt",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
在确定负责的容器后,使用:-
Docker rm -f container-1 container-2
以防运行容器
Docker rm container-1 container-2
如果容器未运行
从主机上完全删除容器。
然后尝试使用以下命令移除卷:-
Docker volume remove <volume-name/volume-id>
我对Docker还是个新手。我正在清理一些初始测试混乱,也无法删除一个卷。我已经停止了所有正在运行的实例,执行了一个docker rmi -f $(docker image ls -q),但仍然收到了来自daemon: unable to remove volume: remove uuid: volume is in use的错误响应。
我做了一个docker系统修剪,它清理了需要删除的最后一个卷:
[0]$ docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
... about 15 containers UUID's truncated
Total reclaimed space: 2.273MB
[0]$ docker volume ls
DRIVER VOLUME NAME
local uuid
[0]$ docker volume rm uuid
uuid
[0]$
Docker系统修剪
要使用此命令,客户机和守护进程API都必须至少为1.25。使用
在客户端上使用docker version命令检查客户端和守护进程的API版本。