Is it possible to extract the Dockerfile from a do

2019-03-09 01:05发布

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?

标签: docker
3条回答
Melony?
2楼-- · 2019-03-09 01:42

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.

查看更多
祖国的老花朵
3楼-- · 2019-03-09 01:52

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.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-03-09 01:59

There is undocker available now. We can install it by using the pip command.

pip install git+https://github.com/larsks/undocker/ 

and use

docker save IMAGE_NAME | undocker -i -o IMAGE_NAME 

to extract the files from docker.

https://github.com/larsks/undocker/

查看更多
登录 后发表回答