Skip to content

Instantly share code, notes, and snippets.

View saranshkarira's full-sized avatar
😾
^

Saransh Karira saranshkarira

😾
^
View GitHub Profile
@saranshkarira
saranshkarira / image_to_dockerfile.sh
Created November 10, 2022 07:55
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