Skip to content

Instantly share code, notes, and snippets.

@eschen42
Created September 2, 2017 15:55
Show Gist options
  • Save eschen42/04dfafc63d14f196389fc5c5b262465b to your computer and use it in GitHub Desktop.
Save eschen42/04dfafc63d14f196389fc5c5b262465b to your computer and use it in GitHub Desktop.
Dump a Docker image as the skeleton of a DockerFile
#!/bin/bash
# emit skeletion of DockerFile for the image given by the first (and only) argument
echo "# Here is a skeleton DockerFile for docker image '$1'"
docker history --no-trunc $1 \
| sed '1 d; s/.* ago [ ]*/RUN /; s/[ ][ ]*[0-9.][0-9.]*[kMG]*B[ ][ ]*$//; s/^RUN .bin.sh -c #.nop. [ ]*//' \
| tac
@eschen42
Copy link
Author

eschen42 commented Sep 2, 2017

quick start

wget https://gist.githubusercontent.com/eschen42/04dfafc63d14f196389fc5c5b262465b/raw/4c7d99edfd574fc54c9493c42f1f6f99d7f17558/docker_image_dump
chmod +x docker_image_dump
docker_image_dump name_or_ID_of_image

introduction

Sometimes I want to see what's in a Docker image, e.g.,

  • a tag that may have been superseded by a subsequent build
  • an image that I want to study without going to the trouble of finding the source for the DockerFile

My intent here is not to produce a runnable DockerFile but rather (without much effort) to emit something that I can read easily.

I searched for "create dockerfile from image" and found the dockerfile-from-image repository, but I couldn't get the docker image to run.

So, I wrote this script that leverages docker history, sed, and tac; it shares many of the limitations of the tool linked above

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