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. Mostly. Notes: It does not generate a Dockerfile that you can use directly with docker build ; the output is just for your reference. It will pull the target docker image automatically and export Dockerfile .
You can create a new image by using docker command $docker build -f docker_filename . , It will first read the Dockerfile where the instructions are written and automatically build the image. The instruction in the Dockerfile contains the necessary commands to assemble an image.
If you want to see the dockerfile, then you can go to docker hub and type the image name and version name in the tag format (e.g ubuntu:14.04) this will open the image along with Docker file details. Also keep in mind, only if the owner of the image shared their Dockerfile, you can see it.
How to generate or reverse a Dockerfile from an image?
You can. Mostly.
Notes: It does not generat a Dockerfile
that you can use directly with docker build
, the output is just for your reference.
alias dfimage="docker run -v /var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage" dfimage -sV=1.36 nginx:latest
It will pull the target docker image automaticlaly and export Dockerfile
. Parameter -sV=1.36
is not always required.
Reference: https://hub.docker.com/repository/docker/alpine/dfimage
Now hub.docker.com shows the image layers with detail commands directly, if you choose a particular tag.
If you want to know which files are changed in each layer
alias dive="docker run -ti --rm -v /var/run/docker.sock:/var/run/docker.sock wagoodman/dive" dive nginx:latest
On the left, you see each layer's command, on the right (jump with tab), the yellow line is the folder that some files are changed in that layer
(Use SPACE to collapse dir)
below is the old answer, it doesn't work any more.
$ docker pull centurylink/dockerfile-from-image $ alias dfimage="docker run -v /var/run/docker.sock:/var/run/docker.sock --rm centurylink/dockerfile-from-image" $ dfimage --help Usage: dockerfile-from-image.rb [options] <image_id> -f, --full-tree Generate Dockerfile for all parent layers -h, --help Show this message
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With