I'm just starting out with Docker, and it would be very helpful to be able to see the Dockerfiles used to create existing docker images.
Even if the image was built by running commands manually, and then committing to a tag, it would be nice to be able to see how the image was made, both for learning purposes and for security.
Is there a way to extract a Dockerfile or list of commands used to build a given docker image?
There's a project dockerfile-from-image which could help you to do it directly.
It requires a single CLI command to recover the Dockerfile:
docker run -v /var/run/docker.sock:/var/run/docker.sock centurylink/dockerfile-from-image <IMAGE_TAG_OR_ID>
One has to have Docker already installed.
You have
docker history <image>
that is very helpful. It can even be used to generate a dockerfile if none of the steps involved stdin.If a step as stdin, the only way to know what happened would be to do
docker logs <container id parent>
, but if you do not have the container, you can't.There is undocker available now. We can install it by using the pip command.
and use
to extract the files from docker.
https://github.com/larsks/undocker/