简体   繁体   English

从docker镜像获取dockerfile / docker命令

[英]Get dockerfile / docker commands from docker image

Is it possible to get back the docker commands which were run to produce a given docker image? 是否有可能返回运行生成给定docker镜像的docker命令? Since each line of a docker file should map to a single layer, it seems this would be possible, but I don't see anything in the docs. 由于docker文件的每一行都应映射到单个图层,所以看起来这是可能的,但我在文档中看不到任何内容。

docker history <image>

几乎就是这样。

You can use combinations of two docker commands to achieve what you want: 您可以使用两个docker命令的组合来实现您的目标:

docker inspect <image>

and

docker history <image>

Or you can use this cool service to see how that image being generated, each layer is a command in your docker file: 或者您可以使用这个很酷的服务来查看生成该图像的方式,每个图层都是docker文件中的命令:

https://imagelayers.io/?images=java:latest,golang:latest,node:latest,python:latest,php:latest,ruby:latest https://imagelayers.io/?images=java:latest,golang:latest,node:latest,python:latest,php:latest,ruby:latest

I guess it depends on where you got the image from. 我想这取决于你从哪里得到图像。

In the case of these docker containers of mine from the Docker Hub you can use this link from the right hand side of the webpage to follow it to this github repo containing the Dockerfile(s) . 对于我的Docker Hub中这些docker容器,您可以使用网页右侧的链接跟随它到包含Dockerfile的github存储库

I do not think there is a command to "unassemble" a container / image and get back the instructions which made it. 我认为没有命令“拆卸”容器/图像并取回制作容器/图像的指令。

Is it possible to get back the docker commands which were run to produce a given docker image? 是否有可能返回运行生成给定docker镜像的docker命令?

No, considering you have commands like docker export / docker import which allows to flatten an image: 不,考虑到你有像docker export / docker import这样的命令可以展平图像:

docker export <containerID> | docker import - <imagename>

The resulting image would be build from a container, and include only one layer. 生成的图像将从容器构建,并且仅包含一个图层。 Not even a docker history would be able to give clues as to the original images and their Dockerfile which where part of the original container. 即使是一个docker history也不能提供关于原始图像和原始容器部分的Dockerfile的线索。

For the images you create image metadata (labels) can be used to store Dockerfile https://docs.docker.com/engine/userguide/labels-custom-metadata/ 对于您创建的图像,图像元数据(标签)可用于存储Dockerfile https://docs.docker.com/engine/userguide/labels-custom-metadata/

Initial solution was proposed here https://speakerdeck.com/garethr/managing-container-configuration-with-metadata 最初的解决方案是在这里提出的https://speakerdeck.com/garethr/managing-container-configuration-with-metadata

This approach of storing Dockerfile is not very efficient - it requires container to be started in order to extract the Dockerfile. 这种存储Dockerfile的方法效率不高 - 它需要启动容器才能解压缩Dockerfile。

I personally use different approach - encode Dockerfile with Base64 and pass such encoded string using external arguments to set image label. 我个人使用不同的方法 - 使用Base64编码Dockerfile,并使用外部参数传递这样的编码字符串来设置图像标签。 This way you can read content of Dockerfile directly from image using inspect. 这样您就可以使用inspect直接从图像中读取Dockerfile的内容。 You can find detailed example here: https://gist.github.com/lruslan/3dea3b3d52a66531b2a1 你可以在这里找到详细的例子: https//gist.github.com/lruslan/3dea3b3d52a66531b2a1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM