Skip to content

Instantly share code, notes, and snippets.

@jairamc
Created November 28, 2016 12:44
Show Gist options
  • Save jairamc/3ac5faf6f4b9d80ab568290e49b262cb to your computer and use it in GitHub Desktop.
Save jairamc/3ac5faf6f4b9d80ab568290e49b262cb to your computer and use it in GitHub Desktop.
Build a Dockerfile from Image
#!/bin/bash
########################################################################################
# This will not build a full dockerfile, but will give a good hint to how it was build #
########################################################################################
docker history --no-trunc "$1" | \
sed -n -e 's,.*/bin/sh -c #(nop) \(MAINTAINER .*[^ ]\) *0 B,\1,p' | \
head -1
docker inspect --format='{{range $e := .Config.Env}}
ENV {{$e}}
{{end}}{{range $e,$v := .Config.ExposedPorts}}
EXPOSE {{$e}}
{{end}}{{range $e,$v := .Config.Volumes}}
VOLUME {{$e}}
{{end}}{{with .Config.User}}USER {{.}}{{end}}
{{with .Config.WorkingDir}}WORKDIR {{.}}{{end}}
{{with .Config.Entrypoint}}ENTRYPOINT {{json .}}{{end}}
{{with .Config.Cmd}}CMD {{json .}}{{end}}
{{with .Config.OnBuild}}ONBUILD {{json .}}{{end}}' "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment