Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Force Docker to release storage space after manual delete of file in volumes and containers?

Tags:

docker

I have few issues with storage spaces. I deleted few big files such as log files (after find unix of big files).

The problem is that delete manually some file of Docker (in /var/lib/docker/...). After deletion of Docker files, I can see that the space left does not change. Docker does not release space.

I restart the service Docker and I the problem persit.

How can I force Docker to release space from (devicemapper, volume, images, ...) ?

like image 501
Youssouf Maiga Avatar asked May 31 '17 15:05

Youssouf Maiga


2 Answers

This depends on what version of docker you are using, If you are using >1.13 then you can use:

docker system df

and

docker system df -v

^^These will show where disk space is being utilized.

You can cleanup using prune commands:

docker system prune -af

^^ This prunes everything & is the most destructive. Or you can use docker image prune or docker volume prune etc.

like image 87
Anoop Avatar answered Oct 18 '22 17:10

Anoop


With recent versions of Docker you can see the space used with:

docker system df

and prune it with:

docker system prune

The above command combines the prune command that exists for volumes, containers, networks and images:

docker volume prune

docker container prune

docker image prune

docker network prune

All of these have a --help option.

-o-

On older versions of Docker I ran the script:

#!/bin/bash

# Remove dead containers (and their volumes)
docker ps -f status=dead --format '{{ .ID }}' | xargs -r docker rm -v
# Remove dangling volumes
docker volume ls -qf dangling=true | xargs -r docker volume rm
# Remove untagged ("<none>") images
docker images --digests --format '{{.Repository}}:{{.Tag}}@{{.Digest}}' | sed -rne 's/([^>]):<none>@/\1@/p' | xargs -r docker rmi
# Remove dangling images
docker images -qf dangling=true | xargs -r docker rmi
# Remove temporary files
rm -f /var/lib/docker/tmp/*
like image 42
Ricardo Branco Avatar answered Oct 18 '22 18:10

Ricardo Branco