caprover
caprover copied to clipboard
Scheduled Disk Cleanup
Is your feature request related to a problem? Please describe. I have a Netdata monitor set up which sends me a notification when it thinks "Out of space time = 7h", which means I've probably done a bunch of deploys in a short period of time, and I should use the "Disk Cleanup" feature to remove older images.
Describe the solution you'd like It would be great if I can schedule Disk Cleanup, say once a day, week, or month. I can set up how many recent images I want to keep, and it — like a cron job — deletes unused images automatically.
Describe alternatives you've considered I can use an API or set up a cron job myself which hits the endpoint to clean up the disk automatically, but it's not very secure since Caprover uses a password-based authentication. It would be super useful to schedule it from within the Caprover UI.
It's a good suggestion, meanwhile, you can use a 3rd party solution like this one: blog: https://marcopeg.com/2019/docker-vacuum github project: https://github.com/marcopeg/docker-vacuum
In case someone ends up wanting to set up docker vacuum with caprover like I did:
- Create an app with persistent data
- Don't expose as a webapp
- Map
/var/run/docker.sock
to/var/run/docker.sock
as a persistent directory - Deploy captain-definition file:
{
"schemaVersion": 2,
"imageName": "marcopeg/docker-vacuum"
}
In case someone ends up wanting to set up docker vacuum with caprover like I did:
- Create an app with persistent data
- Don't expose as a webapp
- Map
/var/run/docker.sock
to/var/run/docker.sock
as a persistent directory- Deploy captain-definition file:
{ "schemaVersion": 2, "imageName": "marcopeg/docker-vacuum" }
I had this working. Unfortunately, maybe with a docker update, the image started throwing errors.
Error: "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"
if an application is set to have 0 instances, would it be at risk to be cleaned up by Vaccum(with default settings)?
Yes please!
I think this is one of the last missing pieces to make CapRover a fully setup and forget system
Not sure if it helps, but what I do is set this in my crontab:
0 3 * * * /usr/bin/docker system prune -af
@seiyria, that might be quite dangerous. If for a reason your apps had stopped, that command will remove all your app containers too. Maybe you can redeploy but there is also a chance for Caprover to break.
Not sure if it helps, but what I do is set this in my crontab:
0 3 * * * /usr/bin/docker system prune -af
This is exactly what I do. But I also use continuous deployment model so just in case something goes wrong, I'm only one click away from a quick re-build from last git commit. So far the docker system prune option has not let me down.
Not sure if it helps, but what I do is set this in my crontab:
0 3 * * * /usr/bin/docker system prune -af
This is exactly what I do. But I also use continuous deployment model so just in case something goes wrong, I'm only one click away from a quick re-build from last git commit. So far the docker system prune option has not let me down.
Update: This bit me. I had turned off a service to back it up then it was gone when I tried to scale it from 0 back to 1. So, I recommend nobody does this.
@seiyria, that might be quite dangerous. If for a reason your apps had stopped, that command will remove all your app containers too. Maybe you can redeploy but there is also a chance for Caprover to break.
As I said before, running that command is actually dangerous. As a temporary solution, I use Portainer. I log into it once in a while and remove unused images. That's a safe solution until Caprover develops a better way.
In case someone ends up wanting to set up docker vacuum with caprover like I did:
- Create an app with persistent data
- Don't expose as a webapp
- Map
/var/run/docker.sock
to/var/run/docker.sock
as a persistent directory- Deploy captain-definition file:
{ "schemaVersion": 2, "imageName": "marcopeg/docker-vacuum" }
@grantcodes
getting this error: exec /bin/sh: exec format error
Usually this error happens when the cpu architecture doesn't match. Are you running on an ARM server by any chance?
Yes! I'm on Hetzner ARM64.
You can try forking the project and use buildx, similar to how CapRover build works. We compile for all CPU architectures.
Here are the relevant lines: https://github.com/caprover/caprover/blob/f9d880e8c3b56adfd0778aed105587c63b599db8/dev-scripts/build_and_push_release.sh#L65-L71
Thank you!
However, I just forked the repo and added a captain-definition file to deploy using dockerfile. It seemed faster. :)