What is the "RECLAIMABLE" space displayed in docker system df? - docker

One can use the command docker system df (mirror) (introduced in Docker 1.13.0) to see docker disk usage, e.g.:
username#server:~$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 44 28 114.7GB 84.84GB (73%)
Containers 86 7 62.43GB 41.67GB (66%)
Local Volumes 2 1 0B 0B
Build Cache 0B 0B
How is the "RECLAIMABLE" displayed in docker system df computed? I.e., what does it represent?
The Docker documentation on docker system df (mirror) doesn't explain it. The Docker glossary (mirror) doesn't contain the term "RECLAIMABLE".

Hi #Franck Dernoncourt!
RECLAIMABLE is the space consumed by "unused" images (in the meaning of no containers based on thoses images is running).
In other words and as #jordanm said, this is the total size of images you can remove without breaking anything, that is exactly why Docker will remove them if you run docker system prune -a or docker image prune -a. The -a tells Docker to remove all unused images, without it Docker only removes dangling (untagged) images.
You can learn more on how optimize your disk space with Docker here and here and of course Docker documentation for docker image prune and docker system prune.

It's worth mentioning in addition to Kerat's answer, the command you may be looking for to free up space listed as RECLAIMABLE is docker system prune -a --volumes. Volumes will not be pruned by default if you don't include the --volumes flag.

Related

How to find active docker images and volumes?

I can see docker disk using the docker system df command:
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 31 1 12.86GB 12.81GB (99%)
Containers 1 0 0B 0B
Local Volumes 25 1 17.24GB 17.19GB (99%)
Build Cache 244 0 6.249GB 6.249GB
The output shows one image and one volume are active. How can I find these active objects?
I don't think I have any active objects because docker ps displays no results. Perhaps these are internally managed docker objects?
docker ps -a solved the problem

inconsistency between "docker system df" and Docker Desktop on Mac

#docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 222 0 42.87GB 42.87GB (100%)
Containers 0 0 0B 0B
Local Volumes 10 0 77.68MB 77.68MB (100%)
Build Cache 946 0 7.982GB 7.982GB
From the docker system df command, it seems my docker disk is running out of space. But Docker desktop shows:
So I am confused which one should be the right one to indicate docker space usage?
If you're on a mac/windows, then it means that behind the scenes you're running a VM running linux. That disk size then corresponds to the VM disk size containing the Linux distro, rather than just the docker stuff.
Actually, the RECLAIMABLE column is basically the size and percentage of the resources that aren't in use, there is no container using these images/volumes. In your case, 100% of the images and volumes are in "Idle" so you can remove them if you want, there are some good ways to remove it like docker image prune and docker system prune.
The image that you sent has what you are looking for.

docker clean up container overhead

I have two docker containers running, where the diskspace is as follows:
user$ sudo docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 2 1 448.3MB 1.84kB (0%)
Containers 2 2 284.4MB 0B (0%)
Local Volumes 7 2 418.8kB 176.4kB (42%)
Build Cache 0 0 0B 0B
If I check diskusage I get:
root:/var/lib/docker# du -ah --max-depth=1
45G ./containers
What can I do to keep the containers (since I made a lot of configuration) but remove the obvious overhead?
Please run the below command the clean the system as
This will remove:
all stopped containers
all networks not used by at least one container
all dangling images
all dangling build cache
docker system prune -f
And yes, you can remove the son file as well.
You can use docker system prune -f, but, from my experience, it is not cleaning all that can be cleaned up.
For that, I've created a simple Docker image that does all the needed cleaning using only one command:
docker run -v /var/run/docker.sock:/var/run/docker.sock tikalci/tci-docker-cleanup:latest
For more details, see: https://github.com/TikalCI/tci-docker-cleanup

Reclaim disk space after removing file from Docker container

I've successfully copied a large database backup file (35 GB) into the Docker container and restored my database locally (following this walkthrough). I want to now delete that .bak file from the Docker container to reclaim the space. I did that by running sudo docker exec sql_server rm -rf /var/opt/mssql/backup/example.bak but this didn’t reclaim the space - my Docker.raw file remains about 76 GB. When I run docker system df it says my containers are 45 GB though. I tried docker system prune -a but this reclaimed 0B. Restarting Docker didn't do the trick. How do I shrink that now that the file is removed in order to gain that space back?
I did that by running sudo docker exec sql_server rm -rf /var/opt/mssql/backup/example.bak but this didn’t reclaim the space
Whether this will free up space depends on whether the file exists only in the container or if it exists in your image. Once a file exists in the image, deleting it in the container doesn't modify the image itself. Instead only the container filesystem is updated with an indication that the file is deleted from the view of that container. This is how the layered filesystem works under the covers.
When I run docker system df it says my containers are 45 GB though
You can examine this a bit deeper. For any specific container, you can run a docker container diff command on the container id to see the files that have been modified inside that container.
I tried docker system prune -a but this reclaimed 0B.
This will not reclaim space from a running container. If the container is stopped, it will be deleted, and the image that started that container may also be deleted if nothing else points to it. Otherwise docker will avoid running containers and there's no pruning it can run on the files inside a running container.
my Docker.raw file remains about 76 GB
This is a very key point, it suggests that you are running Docker on a Mac. All of the above steps may reduce disk space of the Linux environment that Docker runs on top of. However, the VM that Docker uses on Mac and Windows is mapped to a file that grows on demand as the VM needs it. From the Docker for Mac FAQ, diskspace reported by this file may not be accurate because of sparse files work on Mac:
Docker.raw consumes an insane amount of disk space!
This is an illusion. Docker uses the raw format on Macs running the
Apple Filesystem (APFS). APFS supports sparse files, which compress
long runs of zeroes representing unused space. The output of ls is
misleading, because it lists the logical size of the file rather than
its physical size. To see the physical size, add the -ks switch; to
see the logical size in human readable form, add -lh:
$ cd ~/Library/Containers/com.docker.docker/Data/vms/0
$ ls -klsh Docker.raw
2333548 -rw-r--r--# 1 akim staff 64G Dec 13 17:42 Docker.raw
In this listing, the logical size is 64GB, but the physical size is
only 2.3GB.
Alternatively, you may use du (disk usage):
$ du -h Docker.raw
2,2G Docker.raw
I'd also recommend looking at how much disk space is used inside the Docker VM with:
sudo docker run --rm -v /var/lib/docker:/host/var/lib/docker:ro \
busybox df -h /host/var/lib/docker
According to this article, you can flatten a container with:
# export the container to a tarball
docker export <CONTAINER ID> > /home/export.tar
# import it back
cat /home/export.tar | docker import - some-name:latest
docker export exports the container’s filesystem as a tar archive and docker import imports the contents from a tarball to create a filesystem image.
You can avoid using a temporary file by piping directly from docker export to docker import with:
docker export <CONTAINER ID> | docker import - flatten-container:latest

What characterizes a Docker image or container as active?

One can use the command docker system df (mirror) (introduced in Docker 1.13.0) to see docker disk usage, e.g.:
username#server:~$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 44 28 114.7GB 84.84GB (73%)
Containers 86 7 62.43GB 41.67GB (66%)
Local Volumes 2 1 0B 0B
Build Cache 0B 0B
What does "active" mean? I.e., what characterizes an image or a container as active?
The Docker documentation on docker system df (mirror) doesn't explain it. The Docker glossary (mirror) doesn't contain the term "active".
I understand that:
"active" container means that the container is currently running (active containers can be listed with docker ps or equivalently docker container ls).
I believe it means:
Images: there is a container that exists using this image
Containers: container is currently running
Volumes: there is a container that exists with this volume mounted

Resources