I moved you topic to “Docker Engine” since the question has nothing to do with Docker Desktop.
I’m not sure why du gives you smaller size than df, but when one container takes up almost all the disk space, it could be because of large amount of log files in the container or wrong Docker settings and large, not rotated docker logs which is not part of the containers filesystem but is deleted when the container is deleted. The other reason is what you suspect, but I’m not sure you interpret the answer on stackoverflow correctly. Just because you have a lot of operation in the container, it will not use more and more space indefinitely. You have an image filesystem (read-only) and a container filesystem (writeable). You can add new files on the writeable layer, and change them or edit a file which is not on the writeable layer yet. Then in case of overlay2, the data from the read-only filesystem is copied to the writeable layer and you can edit it there. Multiple editing will not copy the files multiple times. When a file is already on the writeable layer, that is a regular file.
So if the issue is the copying a file to the writeable layer, that must be a very big file but you can’t get a bigger size than twice the size of the image. If the size of the container from inside is 4GB, removing the container would not free more then 4GB plus the size of the Docker container log and stopping the container should not free any space. Except when you are not actually killing the container but stopping (sending SIGTERM) and processes can remove files before exiting. The followinf command can take you to the folder of the container in the docker data root:
container=test
cd $(dirname $(docker inspect "$container" --format '{{ .GraphDriver.Data.MergedDir }}'))
Change the value of “container”. Then you can check the size of that folder and what you can find there. There are multiple folders. “diff” stores the everything that changed compared to the image. “merged” has the filesystem you can see from the container containing everything that the read-only layer contained. So when you use du
to determine the size of the docker data root, you should also use the -x
flag, otherwise you would get a bigger size. The interesting thing is that your problem ws not that du showed a bigger size but df. So I can’t explain it and definitely not the big difference.