Docker is in volume in use, but there aren't any Docker containers
Asked Answered
S

13

353

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


I've been having issues with removing Docker volumes with Docker 1.9.1.

I've removed all my stopped containers so that docker ps -a returns empty.

When I use docker volume ls, I'm given a whole host of Docker containers:

docker volume ls
DRIVER              VOLUME NAME
local               a94211ea91d66142886d72ec476ece477bb5d2e7e52a5d73b2f2f98f6efa6e66
local               4f673316d690ca2d41abbdc9bf980c7a3f8d67242d76562bbd44079f5f438317
local               eb6ab93effc4b90a2162e6fab6eeeb65bd0e4bd8a9290e1bad503d2a47aa8a78
local               91acb0f7644aec16d23a70f63f70027899017a884dab1f33ac8c4cf0dabe5f2c
local               4932e2fbad8f7e6246af96208d45a266eae11329f1adf176955f80ca2e874f69
local               68fd38fc78a8f02364a94934e9dd3b5d10e51de5b2546e7497eb21d6a1e7b750
local               7043a9642614dd6e9ca013cdf662451d2b3df6b1dddff97211a65ccf9f4c6d47
#etc x 50

Since none of these volumes contain anything important, I try to purge all the volumes with docker volume rm $(docker volume ls -q).

In the process, the majority are removed, but I get back:

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

For a sizeable portion of them. If I don't have any containers existing in the first place, how are these volumes being used?

Sluggard answered 7/1, 2016 at 15:22 Comment(8)
docker uses reference counting to check if a volume is still in use; this is all done in-memory; this may be a bug or a race condition somehow, which resulted in the container being removed, but the counter not being updated. A restart of the daemon should resolve this, but, yes it's possible there's a bug somewhere. Is there something special in your setup (e.g. Are you using docker-in-docker, Swarm?). Do you use some script or tool to cleanup your containers?Unset
In docker 1.9.0. I try your steps, and can remove all the volumes.Kesha
Hey thanks @Unset restarting the Docker daemon (sudo service docker stop and sudo service docker start) cleared out all of these ghost volumes for me. Moreover, it seems like I am now able to remove volumes without issue using the docker rm -v command. Only notable differences in usage is that I've been using docker-compose on Ubuntu 15.10. I'll report back if I'm ever able to replicate this problem but otherwise it seems like a simple restart will suffice. Thanks!Sluggard
even after reboot it still says docker volume is in use..Denti
If you use docker compose, you can add -v to the down command, to remove the volumes.Leatheroid
docker caches some information abount containers etc. on disk. perhaps there are some left overs which are confusing the system. have you tried cleaning dangling images etc. which might cause an issue? docker rmi $(docker images -f "dangling=true" -q)Statuette
I fixed this by stopping docker then removing the volumes from the file system and starting docker again. service docker stop && rm -rf /var/lib/docker/volumes/TheVolumIdYouWantToRemove && service docker startStonework
I'm on mac and none of the solutions proposed here workHypocoristic
O
513

Perhaps the volume was created via docker-compose? If so, it should get removed by:

docker-compose down --volumes

Credit to Niels Bech Nielsen!

Odorous answered 14/9, 2018 at 7:18 Comment(9)
This works :) It's good to note that this also removes all the containers themselves. This can be unwanted if you changed files in the container that are not on a permanent mount and not in the image.Nonexistence
You just saved my day. None of the force or other optiosn were working. Was it cos this was a config created by compose and there is some conflict between compose and docker reading those moutsTalipes
anyway to only remove a single volume and not all volumes?Farrow
Just make sure, that you are in the same folder where the docker-compose.yaml lives. Otherwise it will not find the volume names. But works - Thanks!Deponent
If you changed the name of the volumes in your compose files, this may result in orphaned containers. There is a warning printed out in the console by docker, and you can add the ` --remove-orphans` flag to clean then you can rm the associated volumesHungary
Generally works for me, for some weird reason this did not work. But I believe it's because I used a docker compose run command which started an independent container that used the volume. Went into the docker GUI and found it lingering in the containers and delete, then this worked.Nidianidicolous
BIG FAT WARNING. This will delete ALL your images in the docker-compose so make sure this is something you want t odoSororate
I think what @RossW means is the following: it will delete your Volumes!!! So if you have a database loaded into your volume be sure you really want to do this! For me the issue still stands. I want to be able to stop my containers and stop the volumes from being used without deleting them.Demosthenes
In addition, since docker compose v2 or docker v24, the typical "might be an orphan" message is missing. If you renamed or modified the compose file in an unclean way, it might just be an old reference to an orphaned setup, so a down --remove-orphans might actually remove the volume in use.Gladsome
V
295

Volume can be in use by one of stopped containers. You can remove such containers by command:

docker container prune

then you can remove not used volumes

docker volume prune
Valois answered 2/4, 2019 at 15:37 Comment(5)
this should be the accepted answer, dunno why people like the answer givenOutstretch
This is definitely the answer to the question posed. The Armageddon script is nice though.Spermine
Yes, this should be the accepted answer. Only this actions helped me also.Olpe
This doesn't help me. Its not deleting at all. I ran this command and after that if i do ls command it still list the all volumesIneffectual
Other observation. docker volume remove <volume_name> works thoughIneffectual
L
260

You can use these functions to brutally remove everything Docker related:

removecontainers() {
    docker stop $(docker ps -aq)
    docker rm $(docker ps -aq)
}

armageddon() {
    removecontainers
    docker network prune -f
    docker rmi -f $(docker images --filter dangling=true -qa)
    docker volume rm $(docker volume ls --filter dangling=true -q)
    docker rmi -f $(docker images -qa)
}

You can add those to your ~/Xrc file, where X is your shell interpreter (~/.bashrc if you're using bash) file and reload them via executing source ~/Xrc. Also, you can just copy paste them to the console and afterwards (regardless the option you took before to get the functions ready) just run:

armageddon

It's also useful for just general Docker clean up. Have in mind that this will also remove your images, not only your containers (either running or not) and your volumes of any kind.

Lawannalawbreaker answered 8/2, 2017 at 14:52 Comment(9)
Per the question, the docker volume rm command was failing. From the comments, the solution appears to be to restart the docker daemon to fix the reference count.Maite
@Maite if you read carefully through the comments, that is not the solution for this: even after reboot it still says docker volume is in use..Halvorsen
holms appears to have a different issue and isn't the one that posted the question. Look up one comment above that.Maite
The gonsales, 👏for the function name but it is spelt armageddonAuctorial
If I designed Docker it would litter myhttpwebservice.dockerimage and mybeerapplicationstorage.dockervolume files in your current directory rather than putting all these magic files into some hidden repositoryLobar
This did not solve my problem. Using docker-compose down --volumes did though (as suggested by @Robert K. Bell)Winding
is this still relevant? What about docker image prune -aRedroot
thanks for the armageddon function! I am using it but am calling it docker-nuke instead.Gobble
WARNING: This will remove all volumes from docker-compose file.Vishinsky
D
69

I am fairly new to Docker. I was cleaning up some initial testing mess and was not able to remove a volume either. I had stopped all the running instances, performed a docker rmi -f $(docker image ls -q), but still received the Error response from daemon: unable to remove volume: remove uuid: volume is in use.

I did a docker system prune and it cleaned up what was needed to remove the last volume:

[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 system prune

The client and daemon API must both be at least 1.25 to use this command. Use the docker version command on the client to check your client and daemon API versions.

Dickens answered 28/2, 2018 at 5:54 Comment(2)
for some reason I had to do this twice before it worked.Neutretto
I had to do the "docker system prune" and then "docker volume rm volume_name". For some reason, prune deleted containers I had already deleted. confused.Puton
H
23

As long as volumes are associated with a container (either running or not), they cannot be removed.

You have to run

docker inspect <container-id>/<container-name>

on each of the running/non-running containers where this volume might have been mounted onto.

If the volume is mounted onto any one of the containers, you should see it in the Mounts section of the inspect command output. Something like this :-

"Mounts": [
            {
                "Type": "volume",
                "Name": "user1",
                "Source": "/var/lib/docker/volumes/user1/_data",
                "Destination": "/opt",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],

After figuring out the responsible container(s), use :-

docker rm -f container-1 container-2 ...container-n in case of running containers

docker rm container-1 container-2 ...container-n in case of non-running containers

to completely remove the containers from the host machine.

Then try removing the volume using the command :-

docker volume remove <volume-name/volume-id>

Halfslip answered 11/11, 2018 at 6:11 Comment(2)
For a useful answer this reaction needs to be extended. Add information on how to check this.Depositary
I bet docker container prune must be enough in most cases.Gnathous
D
18
  1. First prune the unwanted containers with the command:

    docker container prune
    

    (Make sure that you really want to remove your all containers)

  2. After removing all the unwanted containers prune the volume as well using:

    docker volume prune
    
Dilator answered 4/1, 2022 at 17:18 Comment(0)
D
13

Currently you can use what docker offers now for a general and more complete cleaning:

docker system prune

To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:

docker system prune -a
Dyan answered 24/6, 2019 at 5:42 Comment(0)
C
5

You must remove the container that uses that volume first. List all containers by name, even the existed ones:

docker ps --all --format '{{.Names}}'  

Remove a container:

docker rm NAME

After you removed the container you may remove the volume as well. List the volumes:

docker volume ls

Remove the volume:

docker volume remove VOLUME_NAME
Comparable answered 2/10, 2021 at 6:59 Comment(2)
One reason why this sometimes works after 'docker-compose --volumes' doesn't: because an accidental transient container was made via 'docker compose run'Husbandry
nice, but I find even more useful just to run ´docker ps --all'Kapor
I
4

A one liner to give you just the needed details:

docker inspect `docker ps -aq` | jq '.[] | {Name: .Name, Mounts: .Mounts}' | less

search for the volume of complaint, you have the container name as well.

Illaudable answered 10/11, 2020 at 22:56 Comment(2)
What if there are no containers i.e. "docker ps -aq" does not return anything. The how do we find the mount pathSyblesybley
docker volume inspect $(docker volume ls -q) | jq '.[] | {Name: .Name, Mountpoint: .Mountpoint}' will give you the paths of volumes regardless of whether they are in use by a container...Illaudable
C
3

I am pretty sure that those volumes are actually mounted on your system. Look in /proc/mounts and you will see them there. You will likely need to sudo umount <path> or sudo umount -f -n <path>. You should be able to get the mounted path either in /proc/mounts or through docker volume inspect

Celluloid answered 24/2, 2017 at 7:6 Comment(0)
F
1

You can delete it in your Docker Desktop Application. I have already done that and everything is okay. enter image description here Here:)

Frontal answered 19/11, 2022 at 14:26 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Separatrix
OP's problem is that they have volumes which are in use while the containers are no longer running. You can not delete a volume that is in use.Demosthenes
A
-1

When using Docker Desktop and having extensions installed, they can have a docker volume without any container running.

Example:

➜  ~ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
➜  ~ docker volume ls
DRIVER    VOLUME NAME
local     mochoa_pgadmin4-docker-extension-desktop-extension_pgadmin_data
➜  ~ docker volume rm mochoa_pgadmin4-docker-extension-desktop-extension_pgadmin_data 
Error response from daemon: remove mochoa_pgadmin4-docker-extension-desktop-extension_pgadmin_data: volume is in use - [3a453e427e63138c7f52168004805ebd1728d83fcdf242bbce97c2951bd0eadc]

To solve this, open the Docker Desktop and uninstall the extension.

Alexia answered 20/9, 2023 at 12:56 Comment(2)
Yes, that's the problem the OP has. You don't provide any solution or any pointers for a solution.Omura
Sorry. I've updated the answer. But then the solution is to remove the extension.Alexia
B
-4

You should type this command with flag -f (force):

sudo docker volume rm -f <VOLUME NAME>

Boughten answered 26/3, 2018 at 10:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.