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
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
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
4. Force Remove All Volumes
If some volumes still persist, force delete them:
docker volume ls -q | xargs -r docker volume rm -f
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
For older versions:
docker-compose down -v
6. Verify Volumes Are Gone
Finally, check if any volumes remain:
docker volume ls
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)