Skip to content

Instantly share code, notes, and snippets.

@maxweisspoker
Last active August 13, 2024 08:10
Show Gist options
  • Save maxweisspoker/6e772eb7f526a96a5f741c5af89262d6 to your computer and use it in GitHub Desktop.
Save maxweisspoker/6e772eb7f526a96a5f741c5af89262d6 to your computer and use it in GitHub Desktop.
Bash alias to print "Dockerfile" for image by using sed with "docker history"
alias dockerfile='script.sh'
script.sh:
#!/bin/bash
echo "FROM scratch"
docker history --no-trunc $@ | tac | tr -s ' ' | cut -d " " -f 5- | sed 's,^/bin/sh -c #(nop) ,,g' | sed 's,^/bin/sh -c,RUN,g' | sed 's, && , \\\n & ,g' | sed 's,\s*[0-9]*[\.]*[0-9]*\s*[kMG]*B\s*$,,g' | head -n -1
Example usage for Docker Hub image:
$ dockerfile myusername/myimage:latest
@maxweisspoker
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment