Skip to content

Instantly share code, notes, and snippets.

@ike
Last active May 3, 2018 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ike/48d9421dd8b3480a0701f6c1c7ac76a3 to your computer and use it in GitHub Desktop.
Save ike/48d9421dd8b3480a0701f6c1c7ac76a3 to your computer and use it in GitHub Desktop.
docker-up prune
swarm = DockerSwarm.new()
service = Service.new(config.json)
Prune(images? = false, containers? = false, machines? = false)
if images?
images = getServiceImages(service)
for image in images
// Check if image is dangling (old version + not used), then destroy
unless isDangling(image)
image.destroy()
if containers?
containers = getServiceContainers(service)
for container in containers
// Check if container is stopped or orphaned, then destroy
unless isStopped(container) or isOrphaned(container)
container.destroy()
if machines?
...
PruneServices()
services = swarm.getServices()
for service in services
// I assume this would include some business rules, like "is this service for a customer in good standing", as well as
// ops checks like "is this service orphaned for some reason"
unless isNeeded(service)
service.backupSSB()
service.destroy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment