Docker Community Forums

Share and learn in the Docker community.

Working shrinking/flatten/lessen/reducing image workaround


(Beckend) #1

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.


(Nathan Le Claire) #2

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"]

(Beckend) #3

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?