Created
October 27, 2021 17:28
-
-
Save scentoni/5da5b4856551323f87462257d350c991 to your computer and use it in GitHub Desktop.
generate a dockerfile from an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://stackoverflow.com/questions/19104847/how-to-generate-a-dockerfile-from-an-image | |
case "$OSTYPE" in | |
linux*) | |
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 | |
;; | |
darwin*) | |
docker history --no-trunc --format "{{.CreatedBy}}" $1 | # extract information from layers | |
tail -r | # reverse the file | |
sed -E '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 | |
;; | |
*) | |
echo "unknown OSTYPE: $OSTYPE" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment