Giter VIP home page Giter VIP logo

docker-gc's Introduction

Yet another Docker GC

Circle CI

Yet another Docker GC but unlike others :

  • Written in Go and uses the go-dockerclient to talk straight to API (rather than shelling out)
  • Actually have tests
  • Supports manual cleanups in addition to ttl runs
  • Supports reporting errors to Bugsnag
  • Supports sending metrics to dogstatsd

Usage

Compiling

You can compile the binary by doing script/setup and script/compile. Golang 1.5+ and Git 1.7+ is needed

Running

  docker-gc -command=containers|images|all|emergency [-images_ttl=<DURATION>) [-containers_ttl=<DURATION>]
  -command=all cleans all images and containes respecting keep_last values
  -command=emergency same as all, but with 0second keep_last values
  OR
  docker-gc -command=ttl [-interval=<INTERVAL_IN_SECONDS>] [-images_ttl=<DURATION>] [-containers_ttl=<DURATION>] for continuous cleanup based on image/container TTL
  OR
  docker-gc -command=diskspace [-interval=<INTERVAL_IN_SECONDS>] [-high_disk_space_threshold=<PERCENTAGE>] [-low_disk_space_threshold=<PERCENTAGE>] [-containers_ttl=<DURATION>] for continuous cleanup based on used disk space

  You can also specify -bugsnag-key="key" to use bugsnag integration
  and [-statsd_address=<127.0.0.1:815>] and [statsd_namespace=<docker.gc.wtf>] for statsd integration

docker-gc has two main modes; continuous cleanup and one-time cleanup.

One-time cleanup

One-time cleanup can be in four ways (as -command=COMMAND)

  • emergency : clean all containers and images
  • all : clean all containers and images but respect keep_last values
  • images/containers : clean only images or only containers respecting keep_last values

eg. docker-gc -command=all -images_ttl=5m -containers_ttl=1m would do a one time cleanup of images older than 5minutes and containers older than 1minutes

Default values are:

  • command = ttl
  • images_ttl = 10 hours
  • containers_ttl = 1minutes

Continuous mode

docker-gc has two ttl modes; TTL based and free disk space based. This means the daemon keeps running and does swipes per interval settings.

Default value for interval is 60 seconds.

TTL based

eg docker-gc -command=ttl -interval=5m

Same TTL settings for containers and images apply than for One-time cleanup

Free inode/disk space based

eg docker-gc -command=diskspace -interval=5m -high_disk_space_threshold=85 -low_disk_space_threshold=50

Monitors the disk volume used by Docker and if used inodes/disk space hits the high_disk_space_threshold threshold starts cleaning up images in batches of 10 until low_disk_space_threshold is reached.

NOTICE1: for containers we cleanup based on the containers_ttl per `interval because in majority of usecases it makes more senses than looping in batches.

NOTICE2: The amount in batch might be more than 10 if theres multiple images created at same exact moment (accuracy based on UNIX timestamp)

Usage

Development can be done on both OSX and Linux. Tests can be run without Docker, but anykind of manual testing requires your user to have rights to unix:///var/run/docker.sock (eg. be in docker group)

Setup your environment by doing script/setup. Tests can be run with script/test and running the current version with script/run (compile+run+test mode env)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.