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.
问题:
回答1:
docker history <image>
Does pretty much that.
回答2:
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.
回答3:
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
回答4:
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.
回答5:
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