Class: Mrsk::Commands::Prune

Inherits:
Base
  • Object
show all
Defined in:
lib/mrsk/commands/prune.rb

Constant Summary

Constants inherited from Base

Base::DOCKER_HEALTH_LOG_FORMAT, Base::DOCKER_HEALTH_STATUS_FORMAT

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#container_id_for, #initialize, #run_over_ssh

Constructor Details

This class inherits a constructor from Mrsk::Commands::Base

Instance Method Details

#containers(keep_last: 5) ⇒ Object



16
17
18
19
20
21
# File 'lib/mrsk/commands/prune.rb', line 16

def containers(keep_last: 5)
  pipe \
    docker(:ps, "-q", "-a", *service_filter, *stopped_containers_filters),
    "tail -n +#{keep_last + 1}",
    "while read container_id; do docker rm $container_id; done"
end

#dangling_imagesObject



5
6
7
# File 'lib/mrsk/commands/prune.rb', line 5

def dangling_images
  docker :image, :prune, "--force", "--filter", "label=service=#{config.service}", "--filter", "dangling=true"
end

#tagged_imagesObject



9
10
11
12
13
14
# File 'lib/mrsk/commands/prune.rb', line 9

def tagged_images
  pipe \
    docker(:image, :ls, *service_filter, "--format", "'{{.ID}} {{.Repository}}:{{.Tag}}'"),
    "grep -v -w \"#{active_image_list}\"",
    "while read image tag; do docker rmi $tag; done"
end