How to delete a volume in docker if it is being used by containers

Issue

I have a task in which they have sent us to delete a docker volume which has a container associated with it, I would like to know if there is any way to delete the volume without deleting the container that is using it.

I have tried the following but it won’t let me:

sudo docker volume rm -f vol1

It returns the following.

Error response from daemon: remove vol1: volume is in use - [a90d72c647bf7cdf2a3d8d8f0005163f072e4f6da80f27bca7b81f437f2f21d3]

Solution

To remove the volume, you will have to remove/stop the container first. Deleting volumes will wipe out their data. Back up any data that you need before deleting a container.

Stop/Remove the container(s)
Delete the volume(s)
Restart the container(s) (if you did stop)

Answered By – Sahadat Hossain

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published