简体   繁体   中英

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? 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 history <image>

几乎就是这样。

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

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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