1

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]

4 Answers4

3

To delete all containers including its volumes used

sudo docker rm -vf $(sudo docker ps -a -q)
Sardar Faisal
  • 594
  • 5
  • 20
2

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)
Sahadat Hossain
  • 3,583
  • 2
  • 12
  • 19
2

I have found a way, although for this I have to stop the container that uses it and delete it. I leave it here in case anyone is interested, although I would like to know if there is any way to eliminate the volume without touching the container

sudo docker stop <container>
sudo docker rm <container>
sudo docker volume rm <volume>
1

if it was created by compose, see this question see also Docker is in volume in use, but there aren't any Docker containers

and this : Docker is in volume in use, but there aren't any Docker containers

docker-compose down --volumes
KayCee
  • 115
  • 7