问题描述
是否可以从图像生成 Dockerfile?我想知道有两个原因:
我可以从存储库下载图像,但想查看生成它们的配方.
我喜欢保存快照的想法,但一旦我完成,最好有一个结构化的格式来查看所做的工作.
你可以.大部分.
注意:它不会生成可以直接与docker build
一起使用的Dockerfile
,输出仅供参考.
alias dfimage=docker run -v/var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage"dfimage -sV=1.36 nginx:最新
它会自动拉取目标docker镜像并导出Dockerfile
.参数 -sV=1.36
并非总是必需的.
参考:
奖金
如果你想知道每一层改变了哪些文件
别名潜水=docker run -ti --rm -v/var/run/docker.sock:/var/run/docker.sock wagoodman/dive"潜水nginx:最新
左边是每一层的命令,右边(用tab跳转),黄线是那个层中一些文件被改动过的文件夹
(使用 SPACE 折叠目录)
旧答案
以下是旧答案,不再适用.
$ 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用法:dockerfile-from-image.rb [options] -f, --full-tree 为所有父层生成 Dockerfile-h, --help 显示此消息
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 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.
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
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
这篇关于如何从图像生成 Dockerfile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!