Servers

How to free up some space on your server

free up some space on your server

How to free up some space on your server

Space mystery

From time to time I’m doing some maintenance on my server and I found that the free space is gradually going down.
The fact that it went down gradually sets an alarm, something is growing slowly and taking more and more space.

Looking for the culprit

In order to find what takes space on Linux system, the ncdu package can be used.
If you’re using Ubuntu you can install ncdu by using this command:
sudo apt-get install ncdu

After the installation run:

sudo ncdu /

That command will output a nice structure of the folders and files on your server sorted by size.
Please note that if you don’t use sudo, the ncdu will not be able to access all the folders and the results will be partial.

My results

I found a few big files, most of the files were system logs that clogged up the system taking around 1GB.
One file caught my attention because it was huge taking up 8.5GB of space and produced by one docker container.

Cleaning up

System Logs

So the first step is to clean the system journal files.
That can be done by:

journalctl --vacuum-time=30d

Which will delete all the logs older than 30 days.

Or, you can delete by file size (bigger than):

journalctl --vacuum-size=1G

That freed up 1GB of space, awesome!

Docker container logs

Deleting the container logs was a little bit complex.
Container settings can’t be changed when it’s still running.

I’m using Portainer so I found the option to edit and add the max size option to the logging driver.

Now the log file won’t exceed 10MB.

In order to apply this setting to all the new containers, some steps need to be done.

Edit or create the file daemon.json under /etc/docker/
Add that to the file:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m"
  }
}

Save it and restart docker.

That’s it, now docker will limit the logs size.
And I successfully cleaned precious 8.5GB 🙂

I hope it’ll be useful for you!

Did you like it?

Leave a Comment

Your email address will not be published. Required fields are marked *

Skip to content