Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a Dockerfile from an image?

Is it possible to generate a Dockerfile from an image? I want to know for two reasons:

  1. I can download images from the repository but would like to see the recipe that generated them.

  2. 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.

like image 373
user1026169 Avatar asked Sep 30 '13 22:09

user1026169


People also ask

Is it possible to get Dockerfile from image?

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 .

How do I create a docker image from an existing image?

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.

Where is the Dockerfile of 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.


1 Answers

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.

enter image description here

Bonus

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 

enter image description here

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)

Old answer

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 
like image 196
BMW Avatar answered Oct 11 '22 23:10

BMW