Is it possible to generate a Dockerfile from an image? I want to know for two reasons:
I can download images from the repository but would like to see the recipe that generated them.
I like the idea of saving snapshots, but once I am done it would be nice to have a structured format to review what was done.
You can use Portainer.io https://portainer.io/
It's a web app that runs inside a docker container used to manage all (almost) stuff about your containers. Even images recepies.
This is derived from @fallino's answer, with some adjustments and simplifications by using the output format option for docker history. Since macOS and Gnu/Linux have different command-line utilities, a different version is necessary for Mac. If you only need one or the other, you can just use those lines.
Update:
Quote from @aleung's comment:
centurylink/dockerfile-from-image
doesn't work with new version docker. This one works for me:hub.docker.com/r/chenzj/dfimage
You can.
First way
Here is the example to generate the Dockerfile from an exist image
selenium/node-firefox-debug
Another way, which you needn't pull the image to local and no command need be run.
Use above image as sample, you can get Dockerfile commands via below url:
https://imagelayers.io/?images=selenium%2Fnode-firefox-debug:latest
Wait for a while, there will be two windows, the up window lists the layers, the down window lists the command in Dockerfile
The URL format is:
In face, imagelayers.io is built by
Centurylink
A bash solution :
Step by step explanations:
Example:
Update Dec 2018 to BMW's answer
To understand how a docker image was built, use the
docker history --no-trunc
command.You can build a docker file from an image, but it will not contain everything you would want to fully understand how the image was generated. Reasonably what you can extract is the MAINTAINER, ENV, EXPOSE, VOLUME, WORKDIR, ENTRYPOINT, CMD, and ONBUILD parts of the dockerfile.
The following script should work for you:
I use this as part of a script to rebuild running containers as images: https://github.com/docbill/docker-scripts/blob/master/docker-rebase
The Dockerfile is mainly useful if you want to be able to repackage an image.
The thing to keep in mind, is a docker image can actually just be the tar backup of a real or virtual machine. I have made several docker images this way. Even the build history shows me importing a huge tar file as the first step in creating the image...