How to squash layers?

Hello,

I am converting an older buildah,skopeo,podman based image build script to Dockerfile. That worked great, but for some reason the Layers are much more.

In the first step I used Kaniko in our Kubernetes-GitLab build system. That worked great, but Kaniko creates a step with 16 mb which is only 1.36 kB with buildah. So I tried to build the image with Docker instead. The image size is almost the same as the buildah based one, but it way more layers.

Docker build creates for each statement of the Dockerfile a new layer. We have a lot of ARG and ENV. There are also WORKDIR, EXPOSE, VOLUME, ENTRYPOINT and CMD. It is great to have them for public images, but our images don’t need those. Is there a way to squash them?
I have found an outdated --squash parameter, but is there any way to do that in a current Docker version?

In the end I don’t care how many layers it has, the image is not that big. But there are customer with strange requirements that our software may only have 10 layers – whatever that helps.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.