Skip to content

Instantly share code, notes, and snippets.

@saranshkarira
Created November 10, 2022 07:55
Show Gist options
  • Save saranshkarira/92b5ede79b4d720ad3ef214ddd7e0921 to your computer and use it in GitHub Desktop.
Save saranshkarira/92b5ede79b4d720ad3ef214ddd7e0921 to your computer and use it in GitHub Desktop.
give a docker image name as an argument, get approximate dockerfile
#!/bin/bash
docker history --no-trunc --format "{{.CreatedBy}}" $1 | # extract information from layers
tac | # reverse the file
sed 's,^\(|3.*\)\?/bin/\(ba\)\?sh -c,RUN,' | # change /bin/(ba)?sh calls to RUN
sed 's,^RUN #(nop) *,,' | # remove RUN #(nop) calls for ENV,LABEL...
sed 's, *&& *, \\\n \&\& ,g' # pretty print multi command lines following Docker best practices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment