Working shrinking/flatten/lessen/reducing image workaround

I have tried docker squash, docker import/export, but they don’t all work.
My image have reached 7gb and is growing with each update…

How to remove these unwanted history layers and keep only one.

Would be nice to see official solution if possible.

Thank you.

Is rebuilding your image from scratch not possible?

If there are a lot of build artifacts, it’s not totally crazy to do something like:

FROM debian

# Since this script builds and removes everything in a single layer, 
# no build artifacts will be persisted
COPY ./build-and-rm-artifacts.sh /build.sh

RUN /build.sh

ENTRYPOINT ["my-executable"]

I’ll have to rebuild image very time it’s becoming big? It’s kinda frustrating…

Docker file is not an option for me.

Why not creating some official tool for images shrinking?