Docker inverts the Dockerfile file from the container image

Can

Docker reverse generate Dockerfile files from container images? How to operate?

Dec.11,2021

you can use https://hub.docker.com/r/dduvnjak/dockerfile-from-image/

Note that this script applies only to images that exist in the local image repository (what you see when typing docker image ). If you want to generate Dockerfile, for an image that does not exist in the local repository, you first need docker pull.

for example, you can run the following sentence to see the code

$ 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

the generated code is definitely different from the original Dockerfile, especially when it comes to file and directory mapping, you can only get some hashed directories / files, and the portability is completely lost. So it takes some manual editing work to use it.


give up the idea


what do you want?
I think what you need is to package the current container as an image instead of building it again with another image.


You can see something in

Docker history, but there is no way to restore it to dockerfile.

.

so come up with the idea, and then try to find out how to build it.

Menu