Reputation: 3662
I set up docker on my server. I use Jenkins for CI. Those tools are really cool. But, unfortunately, I still can't figure out how to get the wasted space back.
I tried different things proposed on the web and by using them I can only free a part of the wasted space. I need no any history and etc.
I tried different things, like rude docker rm $(docker ps -aq)
and docker rmi $(docker images -q)
while some of containers are running that make them prevented from deletion.
I also tried this script and similar.
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(
docker ps -aq | xargs docker inspect | jq -r '.[] | .Mounts | .[] | .Name | select(.)'
) | xargs -r rm -fr
I would like to expect that after first build of all images I have fixed size of the stuff by applying the clean up commands above. In other words I want the subsequent builds with clean up applied doesn't make the wasted space grow.
But anyway every execution of docker build occupies new space that I can't free up.
The directory /var/lib/docker/overlay grows up and doesn't consider my clean ups eventually.
Where am I wrong?
Upvotes: 3
Views: 4910
Reputation: 3712
In order to remove volumes use:
docker volume prune
In order to remove networks use:
docker network prune
In order to remove all stopped containers use:
docker container prune
In order to remove unused images use:
docker image prune
Upvotes: 2
Reputation: 7516
In the latest versions of Docker, you can now use docker system prune
command (with --all
option for complete cleanup).
https://docs.docker.com/engine/reference/commandline/system_prune/
Upvotes: 4