caprover icon indicating copy to clipboard operation
caprover copied to clipboard

Scheduled Disk Cleanup

Open AnandChowdhary opened this issue 5 years ago • 16 comments

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.

AnandChowdhary avatar Jul 02 '19 14:07 AnandChowdhary

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

githubsaturn avatar Jul 02 '19 16:07 githubsaturn

In case someone ends up wanting to set up docker vacuum with caprover like I did:

  1. Create an app with persistent data
  2. Don't expose as a webapp
  3. Map /var/run/docker.sock to /var/run/docker.sock as a persistent directory
  4. Deploy captain-definition file:
{
  "schemaVersion": 2,
  "imageName": "marcopeg/docker-vacuum"
}

grantcodes avatar Sep 17 '19 14:09 grantcodes

In case someone ends up wanting to set up docker vacuum with caprover like I did:

  1. Create an app with persistent data
  2. Don't expose as a webapp
  3. Map /var/run/docker.sock to /var/run/docker.sock as a persistent directory
  4. 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?"

redrockzee avatar Apr 17 '20 12:04 redrockzee

if an application is set to have 0 instances, would it be at risk to be cleaned up by Vaccum(with default settings)?

negati-ve avatar May 20 '20 05:05 negati-ve

Yes please!

I think this is one of the last missing pieces to make CapRover a fully setup and forget system

cakeslice avatar Oct 22 '20 16:10 cakeslice

Not sure if it helps, but what I do is set this in my crontab:

0 3 * * * /usr/bin/docker system prune -af

seiyria avatar Nov 29 '20 22:11 seiyria

@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.

Turab avatar Dec 11 '20 15:12 Turab

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.

maietta avatar Feb 04 '21 04:02 maietta

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.

maietta avatar Aug 26 '23 17:08 maietta

@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.

Turab avatar Sep 02 '23 14:09 Turab

In case someone ends up wanting to set up docker vacuum with caprover like I did:

  1. Create an app with persistent data
  2. Don't expose as a webapp
  3. Map /var/run/docker.sock to /var/run/docker.sock as a persistent directory
  4. Deploy captain-definition file:
{
  "schemaVersion": 2,
  "imageName": "marcopeg/docker-vacuum"
}

@grantcodes getting this error: exec /bin/sh: exec format error

s-kris avatar Feb 29 '24 09:02 s-kris

Usually this error happens when the cpu architecture doesn't match. Are you running on an ARM server by any chance?

githubsaturn avatar Feb 29 '24 16:02 githubsaturn

Yes! I'm on Hetzner ARM64.

s-kris avatar Feb 29 '24 20:02 s-kris

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

githubsaturn avatar Mar 02 '24 04:03 githubsaturn

Thank you!

However, I just forked the repo and added a captain-definition file to deploy using dockerfile. It seemed faster. :)

Screenshot 2024-03-04 at 12 40 39 PM

s-kris avatar Mar 04 '24 07:03 s-kris

tenor

githubsaturn avatar Mar 05 '24 05:03 githubsaturn