How to Clean Your VPS Server Safely (Ubuntu + Docker + Coolify)
Learn how to safely clean your Ubuntu VPS, free disk space, remove unused Docker resources, and keep your server running smoothly without breaking your applications.
How to Clean Your VPS Server (Step-by-Step Guide for Beginners)
If your VPS has started running slowly, deployments are failing, or you're seeing messages like "No space left on device", don't panic. This guide will walk you through cleaning your server safely—even if you've never used Linux before.
We'll explain what each command does, why you're running it, and what to expect after running it.
Who is this guide for?
- Beginners using Ubuntu VPS
- Coolify users
- Docker users
- Anyone whose VPS is running out of storage
Before You Begin
What is a VPS?
A Virtual Private Server (VPS) is your own computer running in the cloud. It hosts your websites, applications, and databases.
Just like your laptop, your VPS collects temporary files, logs, unused downloads, and old application files over time.
Cleaning these files regularly keeps your server healthy.
Step 1: Connect to Your VPS
You first need to log into your server.
Windows (PowerShell)
Open PowerShell and type:
ssh root@YOUR_SERVER_IP
Example:
ssh root@123.45.67.89
Replace YOUR_SERVER_IP with your VPS IP address.
If this is your first time connecting, you'll see:
Are you sure you want to continue connecting?
Type:
yes
Then press Enter.
Enter your password if requested.
If you're using SSH keys, you'll log in automatically.
Step 2: Check How Much Storage Is Used
Before deleting anything, let's see how full the server is.
Run:
df -h
Example output:
Filesystem Size Used Avail Use%
/dev/sda1 40G 37G 2G 95%
What does this mean?
| Column | Meaning |
|---|---|
| Size | Total storage |
| Used | Storage already used |
| Avail | Free storage left |
| Use% | Percentage used |
If your server is above 85%, it's a good idea to clean it.
Step 3: Find What's Using the Storage
Run:
du -h --max-depth=1 / 2>/dev/null | sort -hr | head -20
This command lists the biggest folders on your server.
Example:
12G /var
8G /home
4G /usr
Don't delete anything yet.
We're only identifying where the storage is being used.
Step 4: If You Use Docker or Coolify
Most developers using Coolify store applications inside Docker.
Check Docker's storage usage:
docker system df
Example:
Images 12GB
Containers 2GB
Volumes 8GB
Build Cache 6GB
Docker often consumes the most storage on a VPS.
Step 5: Clean Ubuntu Package Cache
Whenever Ubuntu installs software, it saves downloaded installation files.
These files are no longer needed after installation.
Run:
sudo apt clean
Nothing important is deleted.
Only temporary installation files are removed.
Step 6: Remove Old Packages
Sometimes Ubuntu keeps packages that are no longer being used.
Remove them:
sudo apt autoremove -y
This safely removes software that your system no longer needs.
Step 7: Clean Old System Logs
Every application writes logs.
Over months, they can grow into several gigabytes.
Check their size:
journalctl --disk-usage
Example:
Archived and active journals take up 1.8G.
Keep only the last seven days:
sudo journalctl --vacuum-time=7d
Or keep only 200MB:
sudo journalctl --vacuum-size=200M
Either option is perfectly fine.
Step 8: Remove Unused Docker Files
Docker stores:
- Old containers
- Old images
- Build cache
- Networks
Many of these are no longer needed.
Clean them:
docker system prune
Docker asks:
Continue? [y/N]
Type:
y
Press Enter.
If you don't want the confirmation:
docker system prune -f
Step 9: Remove Old Docker Images
If you've deployed your application many times, Docker keeps old versions.
Delete images that are no longer used:
docker system prune -a -f
This can free several gigabytes.
Your next deployment may take slightly longer because Docker downloads the images again.
Step 10: Clean Docker Build Cache
Every deployment creates build files.
These build files aren't needed forever.
Check cache size:
docker builder du
Then remove it:
docker builder prune -a -f
This is one of the easiest ways to recover storage.
Step 11: Check Docker Volumes (Important)
Volumes store your important data.
Examples:
- MongoDB
- PostgreSQL
- MySQL
- Redis
- Uploaded files
- Coolify data
View them:
docker volume ls
⚠️ Important
Do NOT run:
docker volume prune
unless you are 100% sure the volumes are no longer needed.
Deleting the wrong volume can permanently erase your database.
Step 12: Remove Large Docker Logs
Containers generate logs every second.
Find large logs:
find /var/lib/docker/containers/ -name "*-json.log" -exec du -h {} + | sort -hr | head
If a log file has become very large, clear it:
find /var/lib/docker/containers/ -name "*-json.log" -size +100M -exec truncate -s 0 {} \;
This clears the logs without stopping your applications.
Step 13: Check Coolify Backups
If you use Coolify, backups may occupy a lot of storage.
Check backup size:
du -sh /data/coolify/backups
Delete only backups you no longer need.
Always keep at least one recent backup.
Step 14: Check Your Storage Again
Now see how much storage you've recovered.
Run:
df -h
Compare it with the first result.
You should now have significantly more free space.
Step 15: Make Sure Everything Still Works
Check your running applications.
docker ps
You should see all your containers running.
Then open your website in a browser.
Make sure:
- Your website loads
- Login works
- Database works
- Images load
- Applications respond normally
If everything works, your cleanup was successful.
How Often Should You Clean Your VPS?
For most servers:
| Server Usage | Recommended Cleanup |
|---|---|
| Personal projects | Every 2–3 months |
| Small business websites | Monthly |
| Production applications | Every 2–4 weeks |
| Frequent deployments | Weekly |
Common Mistakes to Avoid
❌ Deleting Docker volumes without checking them.
❌ Deleting random folders because they're large.
❌ Cleaning logs while debugging an issue.
❌ Removing backups before confirming you have another copy.
❌ Ignoring low disk space warnings.
Quick Cleanup Commands
If you're already comfortable with Linux, these commands perform the most common cleanup tasks:
df -h
docker system df
apt clean
apt autoclean
apt autoremove --dry-run
journalctl --vacuum-time=7d
docker system prune -a
docker builder prune -a
df -h
docker system df
Final Thoughts
Cleaning your VPS doesn't have to be intimidating. By following the steps in this guide, you can safely free up disk space, improve performance, and avoid common storage-related issues without risking your applications or data.
A good habit is to check your server's disk usage once a month and perform a cleanup whenever storage usage exceeds 80%. Regular maintenance keeps deployments smooth, applications responsive, and your VPS ready for future growth.
Whether you're hosting a personal portfolio, a business website, or multiple applications with Docker and Coolify, a little maintenance goes a long way toward keeping your server reliable.
Related Articles
Why Every Small and Medium Business Needs a Professional Website in 2026
Discover how a modern website helps small and medium businesses attract more customers, build trust, and increase sales
How to Turn Your Web App into a Mobile App with Capacitor (Complete Beginner's Guide)
Learn how to transform your existing web application into a native Android and iOS app using Capacitor. A step-by-step guide for developers using Next.js, React, Vue, Angular, or any modern web framework.

Getting Started with Next.js 16: What's New and Why You Should Care
Next.js 16 brings groundbreaking features including the Turbopack stable release, React 19 support, and enhanced server actions. Here's everything you need to know.