Docker eating up space like crazy

i run a linux sql server on my mac and it slowly eats all the space i gave it.
this is the second time this happened to me after already uninstalling and reinstalling my container.
when i go to container files they are all very small and i dont know whats taking up all this space.
i started with about 55 gb remaining and now i have 16gb after about a month of using it when yesterday i had 18gb remaining.
i suspect that the logs are taking up all the space so i tried looking up the issue and trying peopleā€™s fixes to no successā€¦
please help

update:
my docker.raw file is 40gb out of the 64gb i enabled for it.
40gb is still a lot based on the fact i only use sql for school work which isnā€™t a lot
how do i clear junk from the docker.raw file?

Whats the issue? Are the container log files that large? You can limit them:

services:
  myservice:
    image: my-image:latest
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

Doc 1, Doc 2

Note that Docker Desktop is using a VM to run the containers in, so that may require or reserve itā€™s own disk space.

1 Like

hi, i just checked and the log files on my computer are empty.
docker.raw is the issue

The log files of the containers are usually in /var/lib/docker/containers within the VM.

The raw file is probably the virtual disk of the VM. You should be able to find options in Docker Desktop to set the (maximum) disk size.

I am not a Docker Desktop user myself, run all my containers on Linux servers without VMs.

can you send the whole path?
when trying to find /var/lib/docker/containers i get no results

also, my max disk size is set to 64 and that should be more than enough for my school work.
i really donā€™t know whatā€™s taking up all that space.

Try docker system df to get info on space used by Docker.

1 Like

Containers 1 0 40.39GB 40.39GB (100%)

Well, then re-create the container with the log options mentioned. They can be used in a compose file or with docker run command.

Make sure to use volumes or bind mounts to preserve the database files during container upgrade and re-create.

so theres no way to preserve my container and just delete the files in the vm?

Containers are made for isolation and usually throw away. You should prepare accordingly and always persist relevant data.

Either use a volume, that can only be accessed from within containers, or use a bind mount (also using volume command option but with a local host path) to map a local host directory into the container. Usually the Docker images have a description how to handle this, especially the database ones.

Of course you can continuously manually truncate the log files, find the files and run truncate on them within the VM. Something like

find /var/lib/docker/containers/ -type f -name "*-json.log" -exec truncate -s 0 {} \;

As @bluepuma77 suggested multiple times in this topic, everything is in the virtual machine, so you will not find anyhing on your actual host. You can try this:

docker run --rm -it -v /:/host bash ls -la /host/var/lib/docker/containers

Or based on the last suggested command

You can try this to first check the log sizes

docker run --rm -it -v /:/host bash find /host/var/lib/docker/containers/ -type f -name "*-json.log" -exec ls -lh {} \;

So this is how you would truncate the log files:

docker run --rm -it -v /:/host bash find /host/var/lib/docker/containers/ -type f -name "*-json.log" -exec truncate -s 0 {} \;

In this case you will also truncate the log file of the container from which you are running the find command. I tried and worked without breaking Docker Desktop, but I never like messing with the docker data root unless it is really necessary.

In the long term, it is better to reconfigure the container with log limits

1 Like

thank you very much for the help i used the first reply you sent and created a new container with log files limited to 0.01m

i just figured out the problem. every time the container fails to start it creates a 1gb .gdmp file and stores it in var/opt/mssql/log/core.sqlservr.12_18_2024_10_56_44.25.d and thats taking up all my space.
the thing is it creates a different folder every time it fails and stores a dump file there
for example i have:
var/opt/mssql/log/core.sqlservr.12_18_2024_10_56_44.25.d,
var/opt/mssql/log/core.sqlservr.12_18_2024_10_56_53.25.d
and so on.
is there any way to stop this?

This is a functional behavior of the application inside the container. Handling must be either part of the image, or the application itself. You can check the quickstart docs https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver16 and the image description whether there is a setting for if.

If there is no answer to this problem, I would suggest raising an issue in https://github.com/microsoft/mssql-docker/issues, as others will high likely be affected as well, and a fix might benefit everyone :slight_smile:

Update: I found this Issue and this issue which indicate the core dumps might be a silicon emulation bug. Apparently downgrading to Docker Desktop 4.32.0 is a viable workaround for time being.

thank you very much for the answer. iā€™ve been on this problem for a few months :sweat_smile:

I can imagine. Who would have thought thatā€™s the cause of the problem is such a bag of surprises.:smiley:

Still, it wouldnā€™t hurt to still raise an issue in the mssql server repo, and ask if they can implement at least an entry point script that makes sure that up to N core dumps are kept, or core dumps older than N weeks are deleted automatically. That should be a fairly low-hanging fruit.

Please let us know after testing, whether downgrading to 4.32.0 worked for you, so that others can benefit from your experience as well.

i am a beginner in docker and i donā€™t really understand it well so i have no idea what issue i should report or how to fix it :sweat_smile:
as for downgrading, iā€™m sticking to the updated version of docker just because i donā€™t want anything to happen and iā€™ll just delete the dump files manually until i find some way to do it automatically (because i have no idea how to code in terminal and all that)
but thank you very much for the quick answer and solution!

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.