Introduction
This is an article which is focusing on how to remove docker volume. Actually, there is already another article which is discussing on how to be able to remove a docker volume in ‘How to Delete Docker Volume in Microsoft Windows‘. But eventually, there is a trouble upon removing or deleting the docker volume. Below is the exact situation where the removal of the docker volume ends in a failure. Although using the same command of ‘docker volume rm volume_name’, it ends in failure :
C:\Users\Personal>docker volume rm myvolume Error response from daemon: remove myvolume: volume is in use - [b0d40501ad8f9f4a9d896ed7ad1d9d6d0fc9fbfee7a014040fd61541171ca9fb] C:\Users\Personal>
How to Remove Docker Volume in Use in Microsoft Windows
So, how to solve the above problem. Actually, below is the steps which consist of several attempt from the one which end in failure to the one which actually end in a success :
-
First of all, trying to use the ‘–force’ parameter at the end of the command for removing docker volume as follows :
C:\Users\Personal>docker volume rm --force myvolume Error response from daemon: remove myvolume: volume is in use - [b0d40501ad8f9f4a9d896ed7ad1d9d6d0fc9fbfee7a014040fd61541171ca9fb] C:\Users\Personal>
Still, the addition of ‘–force’ parameter at the end of the ‘docker volume rm’ command for removing docker volume is not working. In that case, try to attepmpt for using another possible way in the next step.
-
The next is one stopping the docker container which is assumed currently using the docker volume. That is why removing the volume is not possible is currently is being used. Below is the process by listing the running docker container first :
C:\Users\Personal>docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b0c5e028c40d registry "/entrypoint.sh /etc…" 8 days ago Up 12 hours 0.0.0.0:5000->5000/tcp hub.local d8fc06dd81a5 nginx:latest "/docker-entrypoint.…" 8 days ago Up 12 hours 0.0.0.0:8181->80/tcp web1 C:\Users\Personal>
Try to stop the running container first which is assumed it is used by the docker container with the name of ‘web1’ :
C:\Users\Personal>docker stop d8fc06 d8fc06 C:\Users\Personal>
Then check for the running container once more by typing the following command below :
C:\Users\Personal>docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b0c5e028c40d registry "/entrypoint.sh /etc…" 8 days ago Up 12 hours 0.0.0.0:5000->5000/tcp hub.local C:\Users\Personal>
Next, just remove the volume which is assuming it will work since the docker container used has stop :
C:\Users\Personal>docker volume rm myvolume Error response from daemon: remove myvolume: volume is in use - [b0d40501ad8f9f4a9d896ed7ad1d9d6d0fc9fbfee7a014040fd61541171ca9fb] C:\Users\Personal>
Well, apparently it is still working. So, continue on to the next step as another attempt to remove docker volume :
-
This step is an attempt by actually really disconnect the docker volume from the docker container. Actually, a docker volume can still be used or connected with the docker container. In that case, how to be able to do that completely ?. Since stopping the docker container does not event detach the docker volume ?. Well, there is another command which is useful for that. Just execute the following command :
C:\Users\Personal>docker container prune WARNING! This will remove all stopped containers. Are you sure you want to continue? [y/N] y Deleted Containers: 4366b99977520fad19cccc291ff6ad919ffa7da080514d3b9ca36203b293a36e b0d40501ad8f9f4a9d896ed7ad1d9d6d0fc9fbfee7a014040fd61541171ca9fb 2fa1231804cab61a28e9b43e8733ed02ddc4ec996f5e1c6c8d24988746010eb4 d8fc06dd81a53afd3ffe8e60e24b930e9a15d6a584e1f28542c6c15efe841d0e Total reclaimed space: 4.335kB C:\Users\Personal>
Apparently, the above command will remove the docker container which already stop. So, please be very careful with that. After removing all of the stop docker container completely, just execute the following command to finally remove the docker volume :
C:\Users\Personal>docker volume rm myvolume myvolume C:\Users\Personal>
Finally, it works.