for-mac icon indicating copy to clipboard operation
for-mac copied to clipboard

Docker.raw reserving too much size

Open aitrusgit opened this issue 8 years ago • 93 comments

Expected behavior

Docker.raw should not grow much larger than the space used by docker containers, images, volumes.

Actual behavior

I have very few images downloaded locally, with no active containers and just a two volumes with some data.

➜  com.docker.driver.amd64-linux docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              19                  0                   3.628GB             3.628GB (100%)
Containers          0                   0                   0B                  0B
Local Volumes       2                   0                   803.5MB             803.5MB (100%)
Build Cache                                                 0B                  0B

Nevertheless Docker.raw size is huge!

➜  com.docker.driver.amd64-linux ls -l Docker.raw
-rw-r--r--@ 1 cf  staff  68719476736 Dec  7 10:35 Docker.raw

Information

Diagnose info:

Docker for Mac: version: 17.11.0-ce-mac40 (b2149617ed8d7263c9c035e25fe71d147169348c)
macOS: version 10.13.1 (build: 17B1003)
logs: /tmp/F397F806-6CA7-40E3-9C36-79B5F0ED519D/20171207-103808.tar.gz
[OK]     db.git
[OK]     vmnetd
[OK]     dns
[OK]     driver.amd64-linux
[OK]     virtualization VT-X
[OK]     app
[OK]     moby
[OK]     system
[OK]     moby-syslog
[OK]     kubernetes
[OK]     db
[OK]     env
[OK]     virtualization kern.hv_support
[OK]     slirp
[OK]     osxfs
[OK]     moby-console
[OK]     logs
[OK]     docker-cli
[OK]     menubar
[OK]     disk

aitrusgit avatar Dec 07 '17 13:12 aitrusgit

I also tried to do a full system prune

➜  com.docker.driver.amd64-linux docker volume prune
WARNING! This will remove all volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
033ce3294aa395bbb8c468eba823622d65b5b1d7f042c4a7ebf29826aed6ea40
2901af7dd8d50ae74ad761fe33cc558881d46ab323e7f6ee6eb87c3337ed8508

Total reclaimed space: 803.5MB
➜  com.docker.driver.amd64-linux docker system prune -a
WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all images without at least one container associated to them
        - all build cache
Are you sure you want to continue? [y/N] y
Deleted Images:
untagged: postgres:9.5.4
untagged: postgres@sha256:1480f2446dabb1116fafa426ac530d2404277873a84dc4a4d0d9d4b37a5601e8
deleted: sha256:2417ea518abc0db32cf2fb0d021ce57dab2e16f480ac924000e
52afd07d3b0a4
...
deleted: sha256:b51149973e6a6c4fb1091ef34ff70002ee307e971b9982075cf226004a93c9b7

Total reclaimed space: 3.628GB

Nevertheless Docker.raw size didn't shrink even after restarting docker engine

aitrusgit avatar Dec 07 '17 13:12 aitrusgit

I even tried removing Docker.raw file manually and, after restarting docker, it gets recreated with the same size:

➜  com.docker.driver.amd64-linux ls -l Docker.raw
-rw-r--r--@ 1 cf  staff  68719476736 Dec  7 10:44 Docker.raw

Is that file size independent of my volumes, images, containers? 64 GB is quite a big chunk of data for an small SSD HD.

aitrusgit avatar Dec 07 '17 13:12 aitrusgit

ls -l shows the "size" of the file, not the number of sectors allocated by the filesystem. Try ls -sl:

$ cd ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux
$ ls -sl Docker.raw 
16248952 -rw-r--r--@ 1 user  staff  ` Dec  7 13:57 Docker.raw

In my case Docker.raw is only using 16248952 filesystem sectors which is much less than the maximum file size of 68719476736 bytes. If I download some images then the 16248952 increases, and if I docker system prune then it decreases again.

I think this is working as expected so I'll close the ticket but nevertheless it is a little confusing. Perhaps we could present the current space usage in the UI somehow-- I'll escalate this suggestion to our UI team.

Thanks for the report and for using Docker for Mac!

djs55 avatar Dec 07 '17 14:12 djs55

Just updated to 17.12.0-ce-mac47 on 10.13.2 on a 13" MBA, reset the preferences and deleted all the things. Preferences say the virtual disk image size is 64GB(3.5GB allocated) Previously, my .qcow2 file was ~6.5GB Now ls -sl Docker.raw reads 6840456 -rw-r--r--@ 1 user staff 68719476736 Jan 14 11:03 Docker.raw - 64GB. When I use GrandPerspective, it also reports that the .raw file is 64GB in size, when it used to report that the qcow2 was 6.5GB and it had some images in it, not a fresh install. Looks like there might still be a problem here.

codesman avatar Jan 15 '18 03:01 codesman

I'm on the same version as codesman, and I too am seeing the same problem. My Docker.raw file is 64G even after I cleared all images in my environment.

brown131 avatar Jan 15 '18 15:01 brown131

The 64GB you see is the "logical" size of the image, not the physical size; see Docker.raw consumes an insane amount of disk space! in the documentation:

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:

thaJeztah avatar Jan 16 '18 01:01 thaJeztah

Adding to this information, I believe the issue is that most tools in the Apple ecosystem still rely on information from ls to report on available disk space.

In particular, Apple's own Software Update tool will refuse to install upgrades without reclaiming that space, and removing Docker.raw effectively unblocked the situation for me (by "freeing" 16GB, my predefined size for Docker image).

tjsousa avatar Feb 06 '18 09:02 tjsousa

I was using rsync to do simple backup of my home directory when I discovered the humongous size of Docker.raw. I was able to solve my problem by moving the file to /scratch under Preferences > Disk. It also had an option to switch the size from 64GB to 32GB, which is better, but still very large. I'd rather not backup GBs of zeros or else loose data I actually do want.

Since the file doesn't actually use disk space until it is "filled", I guess this is fine. But additional options for smaller file sizes might still be beneficial in certain situations. All in all I even doubt that the benefit of preallocating all that space is worth the weird side effects and head aches many user will experience because of it. Keep in mind that many not-very-technical users are instructed to install docker for a variety of reasons.

stepmuel avatar Feb 14 '18 02:02 stepmuel

@stepmuel it’s a sparse file, and the usual approach for VM disk images.

This article may be of interest to you; https://gergap.wordpress.com/2013/08/10/rsync-and-sparse-files/amp/

thaJeztah avatar Feb 14 '18 07:02 thaJeztah

I suspect this also causes Finder's "available" number to do strange things. Today I seemed to gain available space by copying data onto my laptop. 😕

matschaffer avatar May 16 '18 03:05 matschaffer

My comments are in congruence with statements posted by djs55; adding that it's unreasonable to think docker.raw consumes, or is reserving too much (disk?) size. Because Docker utilizes the raw format on Macs running the Apple File System (APFS), APFS supports sparse files "while compressing long runs of zeroes representing un-used space" (source: docs.docker.com).

Another option in determining actual disk usage, and complementing djs55:

$ du -h Docker.raw 2,2G Docker.raw

YRM64 avatar May 19 '18 23:05 YRM64

After you delete a large file from inside the Linux VM, will the space be reclaimed from the Docker.raw file? From this stackoverflow question I'm suspecting the answer is no. My suspicion is that Linux does it's normal filesystem delete where it just unlinks the inode reference, but the underlying sectors on the disk are not zeroed out. And without those filesystem bits being zeroed out, APFS will never reclaim the sparse bits of the file. Is there a better option to reclaim that disk space other than wiping the Docker.raw file and starting fresh?

sudo-bmitch avatar Jul 31 '18 22:07 sudo-bmitch

Still eating up way too much space, believe it or not...

jonnyijapan avatar Sep 19 '18 14:09 jonnyijapan

While I understand that the space isn't technically being used, it's still very annoying to have my Mac think I'm running out of space because it sees docker.raw eating up a quarter of my SSD. It causes low space notifications and, as mentioned by @tjsousa, will prevent things like software updates if the system thinks there isn't enough space b/c it views docker.raw as using what ls shows it using. I feel like there must be a way to solve this on Docker's end...

shannon-fluellen-aurea avatar Sep 26 '18 22:09 shannon-fluellen-aurea

Same problem here.

$ docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              10                  6                   1.673GB             1.233GB (73%)
Containers          8                   0                   4.647GB             4.647GB (100%)
Local Volumes       5                   5                   3.529GB             0B (0%)
Build Cache         0                   0                   0B                  0B
$ ls -klsh Docker.raw
37883956 -rw-r--r--@ 1 Ciastek  staff    45G 28 wrz 15:01 Docker.raw

Docker consumes 36GB. It does not react on deleting volumes/containers/files in containers... Restart of docker / system does not work. Only working - resizing of docker available space.

kamil-jakubowski avatar Sep 28 '18 13:09 kamil-jakubowski

Same issue, my 128GB Mac keeps telling me that I'm running out of space every 2 minutes or so because of this, how do I take care of this 64GB Docker.raw space illusion.

ivanlara avatar Oct 03 '18 16:10 ivanlara

I understand how this is supposed to work, but the bottom line is that both ls -sl and du -h docker.raw return that my docker.raw file is 64GB. Doesn't matter how many or few containers I have, as far as macOS 10.13 or 10.14 are concerned, my docker.raw file is 64GB.

Moving my docker.raw file to an external drive freed up a total of 64 GB on the internal drive.

screenshot 10-03-2018 at 3 18 19 p

aviris avatar Oct 03 '18 21:10 aviris

$ ls -lah Docker.raw
-rw-r--r--  1 xxx  staff    60G Oct  4 16:15 Docker.raw

hktalent avatar Oct 04 '18 08:10 hktalent

I have the same issue as everyone else.

Also I have an actual apple sparse image that I use for something else, that image always shows the actual used size and not the provisioned size so it would seem that Docker is not using an actual apple sparse image...

jackfruhecolab avatar Oct 04 '18 13:10 jackfruhecolab

I am experiencing the same issue but it is causing issues.

$ uname -rms Darwin 17.7.0 x86_64 $ docker --version Docker version 18.06.1-ce, build e68fc7a

When I try to run my postgres container I am told that I don't have enough disk space on the device. There's ~35 GB on the disk available, so it's referring to the container's disk space.

When I resize the amount of space available via docker preferences I have made 80GB available (62 GB on disk) everything is happy again, but none of my containers are close to using up the previously set disk allocation

This has only really started being an issue in the last 4-5days s@work ~/go/src/project (develop) $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE postgres 10.4-alpine 962ed899c609 2 months ago 72.9MB docker.elastic.co/elasticsearch/elasticsearch 6.0.1 28259852697e 10 months ago 508MB openlabs/docker-wkhtmltopdf-aas latest c61ee94c7fcb 3 years ago 747MB s@work ~/go/src/project (develop) $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 72918cb8860c openlabs/docker-wkhtmltopdf-aas "usr/local/bin/gunic…" 24 minutes ago Up 24 minutes 0.0.0.0:8800->80/tcp tap-wkhtmltopdf-aas b9b5789999b5 docker.elastic.co/elasticsearch/elasticsearch:6.0.1 "/usr/local/bin/dock…" 25 minutes ago Up 25 minutes 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp tap-elasticsearch 7366131f37b3 postgres:10.4-alpine "docker-entrypoint.s…" 25 minutes ago Up 25 minutes 0.0.0.0:5432->5432/tcp tap-database

shaneHowearth avatar Oct 04 '18 23:10 shaneHowearth