Skip to content

Instantly share code, notes, and snippets.

@mplewis
Created March 22, 2019 03:26
Show Gist options
  • Save mplewis/25a7090b36e42cd9d27d6551409e0e5a to your computer and use it in GitHub Desktop.
Save mplewis/25a7090b36e42cd9d27d6551409e0e5a to your computer and use it in GitHub Desktop.
inspect a docker image's commands without having its dockerfile
#!/usr/bin/env ruby
# ceto
# from cetology: the scientific study of whales
# inspect a docker image's commands without having its dockerfile
# bash scripting stuff that probably needs to be broken up for visibility
SPECIALS = %w(
$\(
\)
|
if
then
else
fi
)
def cleanup(c)
c.gsub!(/^\/bin\/sh -c #\(nop\)\s+/, '')
c.gsub!(/^(\|\d+ DOCKER_GROUP=\d+ )?\/bin\/sh -c/, 'RUN')
c.gsub!('&&', "&& \\\n")
c.gsub!(';', "; \\\n")
c.gsub!(/!\n\s\s+/, " \\\n")
SPECIALS.each { |s| c.gsub! s, "#{s} \\\n" }
c
end
id = ARGV.first
if !id || (%w(-h --help).include? id)
print <<~MSG
Usage: ceto <docker_image_id>
MSG
exit 1
end
raw = `docker history --format '{{.CreatedBy}}' --no-trunc #{id}`
raw_cmds = raw.split("\n").reverse
clean_cmds = raw_cmds.map { |c| cleanup c }
puts clean_cmds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment