Get dockerfile / docker commands from docker image

2020-03-04 07:48发布

Is it possible to get back the docker commands which were run to produce a given docker image? 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
5条回答
Viruses.
2楼-- · 2020-03-04 07:55

You can use combinations of two docker commands to achieve what you want:

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:

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

查看更多
相关推荐>>
3楼-- · 2020-03-04 07:58

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

I do not think there is a command to "unassemble" a container / image and get back the instructions which made it.

查看更多
叛逆
4楼-- · 2020-03-04 08:02

For the images you create image metadata (labels) can be used to store Dockerfile https://docs.docker.com/engine/userguide/labels-custom-metadata/

Initial solution was proposed here 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.

I personally use different approach - encode Dockerfile with Base64 and pass such encoded string using external arguments to set image label. This way you can read content of Dockerfile directly from image using inspect. You can find detailed example here: https://gist.github.com/lruslan/3dea3b3d52a66531b2a1

查看更多
混吃等死
5楼-- · 2020-03-04 08:09

Is it possible to get back the docker commands which were run to produce a given docker image?

No, considering you have commands like docker export / docker import which allows to flatten an image:

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.

查看更多
\"骚年 ilove
6楼-- · 2020-03-04 08:16
docker history <image>

Does pretty much that.

查看更多
登录 后发表回答