10

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, ...) ?

Youssouf Maiga
  • 6,701
  • 7
  • 26
  • 42

3 Answers3

25

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/*
Ricardo Branco
  • 5,740
  • 1
  • 21
  • 31
  • 1
    Be careful though. `docker prune` is very greedy and may delete even too much. I didn't expect stopped containers to be deleted, rather just their image. – k0pernikus Jun 02 '17 at 09:36
  • 1
    @k0pernikus I can confirm that on version 18.09.1 you receive a verbose message beforehand: WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all dangling images - all dangling build cache Are you sure you want to continue? – Mohsen Kamrani Mar 05 '19 at 02:23
7

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.

Robert
  • 33,429
  • 8
  • 90
  • 94
Anoop
  • 1,406
  • 2
  • 13
  • 20
3

Docker cleanup job is rather non-existing and you are basically in charge of doing it yourself. There are ways of doing that as pointed out in this blog-post, yet I rather use third-party scripts, e.g.: docker-clean to clean up some of the mess docker leaves behind.

k0pernikus
  • 60,309
  • 67
  • 216
  • 347