"/var/lib/docker filling up server space, docker system prune -a removes running containers"

My server’s /var/lib/docker directory is gradually filling up all available disk space, causing downtime.

When I run docker system prune -a to clean up, it removes my running containers as well, which I don’t want.

Questions:

  1. Why is /var/lib/docker growing so large?
  2. How can I safely clean up space without affecting running containers?
  3. What’s the best practice to prevent this?

Environment:

  • Docker version: [add your version]
  • OS: [add your OS]
  • Disk usage: [run du -sh /var/lib/docker/* to see what’s using space]

I’ve tried:

  • docker system prune -a

I think you forgot to share the details in the template that I assume you used.

system prune should not rmove running containers, only unused images, but we can’t tel if it is a bug or using the wrong Docker without knowing what you use. Regarding growing docker data root, usually large amount of logs sent to the standard output or writing files to the container filesystem can fill up the space. Especially when the container is failing and restarting.

Let me share the template that includes the questions that help us to understand the issue:

We usually need the following information to understand the issue:

  1. What platform are you using? Windows, Linux or macOS? Which version of the operating systems? In case of Linux, which distribution?

  2. How did you install Docker? Sharing the platform almost answers it, but only almost. Direct links to the followed guide can be useful.

  3. On debian based Linux, the following commands can give us some idea and recognize incorrectly installed Docker:

    docker info
    docker version
    

    Review the output before sharing and remove confidential data if any appears (public IP for example)

    dpkg -l 'docker*' | grep '^ii'
    snap list docker
    

    When you share the outputs, always format your posts according to the following guide: How to format your forum posts

  1. Linux , Ubuntu 24.04 live server
  2. i installed docker using sudo apt install docker.io
  3. docker client & docker server versions are 28.2.2.
  4. docker.io 28.2.2-0ubuntu1~24.04.1 amd64 Linux container runtime

docker.io is supported by the maintainers of the Linux distribution, not Docker. The officially supported and recomended Docker engine is Docker CE as described here.

It starts with deleting docker.io

Can you install that? If not, we can focus on the space usage, which is not likely to be different in the two engines, but if you found a bug in docker.io it would be better if you could reproduce it with Docker CE before reporting it to Docker. There are also newer Docker versions. 28.5.2 is the latest of v28 and there is also v29, so if there was an actual bug that removed containers, it is likely that it was already fixe din newer versions.

Nowadays, it’s:

du -shx /var/lib/docker/*
du -shx /var/lib/containerd/*

The -x ensures that only files are counted that exist to the file system itself.