DEV Community

Documendous
Documendous

Posted on

How to Fully Remove Docker Volumes (Even When They Persist)

Docker makes it easy to manage containers, but cleaning up unused resources—especially volumes—can sometimes be tricky. If you've run docker system prune --volumes -f but still see volumes when you run docker volume ls, this guide will help you fully remove them.

1. Check for Running Containers

Before removing volumes, ensure that no running or stopped containers are using them:

docker ps -a
Enter fullscreen mode Exit fullscreen mode

If no containers are listed, proceed to the next step.

2. Remove Stopped Containers

Even stopped containers can hold onto volumes. Run:

docker ps -aq | xargs -r docker rm -f
Enter fullscreen mode Exit fullscreen mode

If there are no containers, this command does nothing because of the -r flag in xargs.

3. Remove Unused Volumes

Now, try pruning all unused volumes:

docker volume prune -f
Enter fullscreen mode Exit fullscreen mode

4. Force Remove All Volumes

If some volumes still persist, force delete them:

docker volume ls -q | xargs -r docker volume rm -f
Enter fullscreen mode Exit fullscreen mode

5. Check for Docker Compose Dependencies

If you're using Docker Compose, some volumes might still be referenced. Ensure all services are shut down:

docker compose down -v
Enter fullscreen mode Exit fullscreen mode

For older versions:

docker-compose down -v
Enter fullscreen mode Exit fullscreen mode

6. Verify Volumes Are Gone

Finally, check if any volumes remain:

docker volume ls
Enter fullscreen mode Exit fullscreen mode

Conclusion

If volumes still persist after these steps, they may have been created using a different storage driver or defined outside of Docker’s normal management. In that case, you may need to manually remove them from the host system. Let me know if you run into any issues!

Top comments (0)