1

I have a docker image only.

Is it possible to get the Docker file that was used to build it?

If so, how?

Reason for that is that I loaded the image, so I don't have the Docker file that originated it.

Thanks!

1

2 Answers 2

3

There is a docker container(!) that does this (with some limitations), it is called dockerfile-from-image

https://github.com/CenturyLinkLabs/dockerfile-from-image

have a look at the (Ruby) code

https://github.com/CenturyLinkLabs/dockerfile-from-image/blob/master/dockerfile-from-image.rb

example launching this container to analyse itself

$ docker run --rm -v /run/docker.sock:/run/docker.sock centurylink/dockerfile-from-image
Usage: dockerfile-from-image.rb [options] <image_id>
    -f, --full-tree                  Generate Dockerfile for all parent layers
    -h, --help                       Show this message

and then if you launch it

$ docker run --rm -v /run/docker.sock:/run/docker.sock centurylink/dockerfile-from-image ruby
FROM buildpack-deps:latest
RUN useradd -g users user
RUN apt-get update && apt-get install -y bison procps
RUN apt-get update && apt-get install -y ruby
ADD dir:03090a5fdc5feb8b4f1d6a69214c37b5f6d653f5185cddb6bf7fd71e6ded561c in /usr/src/ruby
WORKDIR /usr/src/ruby
RUN chown -R user:users .
USER user
RUN autoconf && ./configure --disable-install-doc
RUN make -j"$(nproc)"
RUN make check
USER root
RUN apt-get purge -y ruby
RUN make install
RUN echo 'gem: --no-rdoc --no-ri' >> /.gemrc
RUN gem install bundler
ONBUILD ADD . /usr/src/app
ONBUILD WORKDIR /usr/src/app
ONBUILD RUN [ ! -e Gemfile ] || bundle install --system
Sign up to request clarification or add additional context in comments.

Comments

2

You can view the commands were run to create each layer in an image - a sort of peek at the Dockerfile in effect - by running the following:-

docker history [IMAGE] | awk 'NR>1 {print $1}' | xargs docker inspect --format '{{ ((index .ContainerConfig.Cmd ) 0) }}'

If you just did a docker pull [IMAGE] then you can explore the Dockerfile in the standard repo:-

https://hub.docker.com/explore/
https://github.com/docker-library/official-images

```

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.