Webmasters often receive an “error response from daemon: unable to remove volume” message while attempting to remove a volume in Docker.
As a part of our Server Management Services, we help our Customers to fix Docker related errors regularly.
Let us today discuss the possible causes and fixes for this error.
What causes error response from daemon: unable to remove volume?
Docker allows us to quickly build, test, and deploy applications as portable containers that can run virtually anywhere.
Sometimes, applications may need to share access to data or persist data after a container is deleted. Databases, user-generated content for a web site and log files are just a few examples of such data.
Persistent access to data is provided with Docker Volumes.
Docker quickly accumulates a large number of unused objects. It consumes significant disk space and clutters the output produced by the Docker commands. As docker doesn’t remove unused objects such as containers, images, volumes, and networks implicitly, we may need to remove them manually.
We can remove a volume “DataVolume2” using the command:
$ docker volume rm DataVolume2
Sometimes, while removing a Docker volume, it results in the error given below:
Error response from daemon: unable to remove volume: remove DataVolume: volume is in use - [d0d2233b668eddad4986313c7a4a1bc0d2edaf0c7e1c02a6a6256de27db17a63]
This generally happens when the volume is still in use by the container. Docker will not let us remove a volume if it is referenced by a container.
Let us now look at the steps to fix this error.
How to fix error response from daemon: unable to remove volume?
To fix this error, we need to remove the container before removing the volume. From the error message that we saw earlier, the part highlighted in bold indicates the ID of the container that refer to the volume.
We can use this ID to remove the container:
$ docker rm d0d2233b668eddad4986313c7a4a1bc0d2edaf0c7e1c02a6a6256de27db17a63
Removing the container will not affect the volume. The ls command will still list this volume.
$ docker volume ls
As we have removed the container, the volume is now free for deletion. We can use the rm command to delete the Docker volume “DataVolume2”:
$ docker volume rm DataVolume2
[Need any further assistance in fixing Docker errors? – We’re available 24*7]
Conclusion
In short, the message “error response from daemon: unable to remove volume” triggers while attempting to remove a volume in Docker. It generally happens when the volume is still in use by a container. Today, we saw how our Support Engineers fix this error.
Thank you! I’m not very good at Docker yet and was running into this error. For some reason, the container in question wasn’t showing in the list of containers. Maybe it was only showing running containers, not stopped ones. Not sure. But, I was able to remove it using the rm command, which allowed me to remove the volume.
Glad to know that our article helps you solves the issue.
thanks, it works.