How to show a dockerfile of image docker

Carlos Andres picture Carlos Andres · Feb 10, 2018 · Viewed 14.5k times · Source

I download a image from docker repository and Im trying to display the Dockerfile of 'X' image to create my own Dockerfile with the same structure to experiment with him. Im using this command:

docker inspect --format='{{.Config.Image}}' 'here paste the id of image'

That command return a 'sha256', some like this:

sha256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

but I need a command to display a json file with configuration of Dockerfile. Someone know how can I do this? Sorry if the format or the question is not ok, Im a beginner!

Thanks everyone!

Answer

VonC picture VonC · Feb 10, 2018

The raw output, as described in "How to generate a Dockerfile from an image?", would be:

docker history --no-trunc <IMAGE_ID>

But a more complete output would be from CenturyLinkLabs/dockerfile-from-image

docker run -v /var/run/docker.sock:/var/run/docker.sock \
 centurylink/dockerfile-from-image <IMAGE_TAG_OR_ID>

Note there were limitations.

In 2020, as illustrated here:

docker run -v /var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage \
  -sV=1.36 <IMAGE_TAG_OR_ID>