Skip to content

Instantly share code, notes, and snippets.

@akm
Last active June 14, 2022 05:12
Show Gist options
  • Save akm/a4e1af83b76e59395ca68487aba3d8c3 to your computer and use it in GitHub Desktop.
Save akm/a4e1af83b76e59395ca68487aba3d8c3 to your computer and use it in GitHub Desktop.
ARGV.each do |keyword|
image_family_names = `docker search #{keyword} --format '{{.Name}}'`.split("\n")
puts( (["image family names:"] + image_family_names).join("\n") )
image_family_names.each do |image_family_name|
tags = `curl -s https://registry.hub.docker.com/v1/repositories/#{image_family_name}/tags | jq -r '.[].name'`.split("\n")
puts("#{image_family_name} tags: #{tags.join(',')}")
tags.each do |tag|
image_name = image_family_name + ':' + tag
file_name = image_family_name.gsub('/', '-') + '-' + tag + '.tar.gz'
if File.exist?(file_name)
puts "#{image_name} is already exists"
next
end
puts "#{image_name} is in PROGRESS. Backup to #{file_name}"
begin
system("docker pull #{image_name} && docker save #{image_name} | gzip > #{file_name}", exception: true)
rescue => e
puts "#{image_name} Got an error #{e.inspect}"
end
puts "#{image_name} is DONE. Backup to #{file_name}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment